Gautam Buddha Temple Varanasi,Varanasi - Buddhist Pilgrimage

Monday, January 13, 2014

Some basic linq to object query example.

Here code sample uses where clause to find all elements of an array which is less than 4.
  public void Sample1()   
   {   
     int[] num = { 8, 2, 4, 1, 5, 0, 2, 6, 7, 9 };   
     var objNum = from n in num   
                           where n < 4   
                           select n;   
     Console.WriteLine("Numbers < 4:");   
     foreach (var n in objNum)   
     {   
       Console.WriteLine(n);   
     }   
   }  

No comments:

Post a Comment