.NET - LINQ - C# - Basics - Examples - The Three Parts of a LINQ Query


/ Published in: C#
Save to your folder(s)

Snippet to illustrate the three actions that happen in all LINQ query operations.


Copy this code and paste it in your HTML
  1. // The Three Parts of a LINQ Query:
  2.  
  3. // 1. Data source.
  4. int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
  5.  
  6. // 2. Query creation.
  7. // numQuery is an IEnumerable<int>
  8. var numQuery =
  9. from num in numbers
  10. where (num % 2) == 0
  11. select num;
  12.  
  13. // 3. Query execution.
  14. foreach (int num in numQuery)
  15. {
  16. Console.Write("{0,1} ", num);
  17. }

URL: http://msdn.microsoft.com/en-us/library/bb397906.aspx

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.