EnumerableOfType
EnumerableOfType refers to the LINQ extension method OfType<T>, defined in System.Linq. Enumerable.OfType<TResult>(this IEnumerable source) returns all elements of the input sequence that are of type TResult, discarding any that are not. It operates on non-generic sequences as well as generic ones and yields the results with deferred execution.
The method filters by runtime type. As it enumerates the source, it checks each element: if the
OfType<T> supports any reference type as TResult and any value type as well where appropriate. If the
Compared with Cast<T>, OfType<T> does not throw on elements that cannot be cast. Cast attempts to cast
For IQueryable sequences, a similar operator exists as Queryable.OfType<TResult>, enabling type-based filtering in provider-based queries. Example:
In summary, EnumerableOfType provides a safe, deferred-execution means to select elements of a specific type from