Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Single gives you some guarantees about the returned value. Use First/FirstOrDefault if you don't need those guarantees. You can also provide predicate for FirstOrDefault to select First element that matches your predicate.

> Enumerable.Single Method - Returns a single, specific element of a sequence.

Some overload descriptions:

- Returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists.

- Returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enu...

> Enumerable.FirstOrDefault Method - Returns the first element of a sequence, or a default value if no element is found.

https://learn.microsoft.com/en-us/dotnet/api/system.linq.enu...



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: