What are the LINQ Single(), and SingleOrDefault() functions?
What are the LINQ Single(), and SingleOrDefault() functions?
486
12-Feb-2025
Updated on 24-Oct-2025
Ashutosh Kumar Verma
12-Feb-2025Single() vs SingleOrDefault() in LINQ (C#)
Single() and SingleOrDefault() are both used to retrieve a single, unique element from a collection, but they behave differently when the collection contains zero, one, or more than one element.
Single()
Example-
SingleOrDefault()
nullfor reference types,0for numeric types).When to use what?
Final Example-
Also, Read: Explain the ElementAt(), and ElementAtOrDefault() functions in LINQ with C#.