Showing posts with label What is the difference between FirstOrDefault() and SingleOrDefault() extension method in LINQ. Show all posts
Showing posts with label What is the difference between FirstOrDefault() and SingleOrDefault() extension method in LINQ. Show all posts

Friday 30 March 2012

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

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.