In the interests of readability, code that can be simplified should be simplified. To that end, there are several ways https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.ienumerable-1[IEnumerable] language integrated queries (LINQ) can be simplified.
This not only improves readabilty but can also lead to improved performance.
* Use https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.oftype[OfType] instead of https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.select[Select] with the https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast#as-operator[as operator] to type cast elements and then null-checking in a query expression to choose elements based on type.
* Use `OfType` instead of using https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.where[Where] and the https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/type-testing-and-cast#is-operator[is operator], followed by a cast in a `Select`
* Use an expression in `Any` instead of `Where(element => [expression]).Any()`.
* Use the https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.count[Count] or https://learn.microsoft.com/en-us/dotnet/api/system.array.length[Length] properties instead of the https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.count[Count() method] when it's available (unless you use the predicate parameter of the method for filtering).
* Don't call https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.toarray[ToArray()] or https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.tolist[ToList()] in the middle of a query chain.
Using https://learn.microsoft.com/en-us/ef/[Entity Framework] may require enforcing client evaluations. Such queries should use https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.asenumerable[AsEnumerable()] instead of `ToArray()` or `ToList()` in the middle of a query chain.