There are multiple places in an Open Source Project (OSP) code I contribute, where it has to be determined if an element in a collection satisfies a certain condition.
The enumeration in Any()
stops as soon as it finds a matching item as well:
https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.any
I would expect the performance to be very similar. Note that the FirstOrDefault
version won't work with a collection of value types (since the default isn't null) but the Any
version would.