Geeks With Blogs
Berthin Ramampiandra July 2011 Entries
Linq: How to use First() and FirstOrDefault() methods properly
First() and FirstOrDefault() are two extension methods of the Enumerable class. Extension method is a static method that we can call from an instance object which implement IEnumerable interface. Lets make an analysis of the following simple example. 1:int[] number = { 1, 5, 6, 8, 20, 15, 34, 67, 98, 12, 23 }; 2:var num = number.Where(n => n > 100).First(); 3:Console.WriteLine("First Number greater than 100: {0}", num); By definition, First() method return the first element of a sequence. So ......

Posted On Friday, July 22, 2011 9:30 PM

Copyright © berthin | Powered by: GeeksWithBlogs.net | Join free