Enumerable::OfType<TResult> Method (IEnumerable^)
Filters the elements of an IEnumerable based on a specified type.
Assembly: System.Core (in System.Core.dll)
public: generic<typename TResult> [ExtensionAttribute] static IEnumerable<TResult>^ OfType( IEnumerable^ source )
Return ValueType: System.Collections.Generic::IEnumerable< >^
An IEnumerable<T> that contains elements from the input sequence of type TResult.
The type to filter the elements of the sequence on.
This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action. The query represented by this method is not executed until the object is enumerated either by calling its GetEnumerator method directly or by using foreach in Visual C# or For Each in Visual Basic.
This method is one of the few standard query operator methods that can be applied to a collection that has a non-parameterized type, such as an ArrayList. This is because extends the type IEnumerable. cannot only be applied to collections that are based on the parameterized IEnumerable<T> type, but collections that are based on the non-parameterized IEnumerable type also.
By applying IEnumerable, you gain the ability to query the collection by using the standard query operators. For example, specifying a type argument of Object to would return an object of type IEnumerable<Object> in C# or IEnumerable(Of Object) in Visual Basic, to which the standard query operators can be applied.to a collection that implements
Available since 8
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1