Filters the elements of an IEnumerable based on a specified type.
Assembly: System.Core (in System.Core.dll)
[ExtensionAttribute] public: generic<typename TResult> static IEnumerable<TResult>^ OfType( IEnumerable^ source )
The type to filter the elements of the sequence on.
Return ValueType: System.Collections.Generic::IEnumerable<>
An IEnumerable<T> that contains elements from the input sequence of type TResult.
Usage NoteIn Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
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.
The method returns only those elements in source that can be cast to type TResult. To instead receive an exception if an element cannot be cast to type TResult, use Cast<TResult>(IEnumerable).
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 to a collection that implements 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.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.