What is the difference between FirstOrDefault() and SingleOrDefault() extension method in LINQ ?

 Posted by Akiii on 3/6/2012 | Category: LINQ Interview questions | Views: 7462 | Points: 40

FirstOrDefault() = gets the first item that matches a given criteria.

SingleOrDefault() = if you specify this extension method that means you are specifically saying that there can be only one value that matches the criteria. If there are more then 1 value that matches the criteria, throw an exception.

Thanks and Regards

Source: weblogs.asp.net | | Alert Moderator 

Comments or Responses

Login to post response