4 ms·
Direct Casting vs. As and Linq Single, SingleOrDefault, First, FirstOrDefault
- douche 12y agoI find that I tend to use SingleOrDefault/FirstOrDefault, combined with an immediate null check, so that I can throw an exception with a more meaningful error message than "Sequence contains no elements" or "Sequence contains more than one matching element", particularly in Release builds that strip line numbers from log messages.