Posted By

denakitan on 04/19/12


Tagged

query Net basics examples Linq parts c#


Versions (?)

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


 / Published in: C#
 

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

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

  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. }

Report this snippet  

You need to login to post a comment.