If you find this article useful, consider making a small donation to show your support for this web site and its content.
DiscountASP
AboutMe
About me:
Hi. My name is Farooq Kaiser and I'm a software developer from Toronto, Canada.

Anonymous types with linq

by Farooq Kaiser 14. January 2009 04:17

I would like to show you the anonymous types with linq in c#.

     Let's say we have an array and we would like to use linq.
       
      var num = new int[] {0, 1, 2, 3, 4, 5};
            var q = from n in num select n;

            foreach (var n in q)
                Console.WriteLine(n);

       The output will be:-  
0
1
2
3
4
 
       and if you want to see them in reverse order.
      
       var q = from n in num orderby n descending select n;
 
        Now, the output will be:-  
5
4
3
2
1
        

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

.NET

Jobs Autos Real estate Videos Power by Google
awesome comments