Enumerable::Cast<TResult> Method (IEnumerable^)
Casts the elements of an IEnumerable to the specified type.
Assembly: System.Core (in System.Core.dll)
public: generic<typename TResult> [ExtensionAttribute] static IEnumerable<TResult>^ Cast( IEnumerable^ source )
Return ValueType: System.Collections.Generic::IEnumerable< >^
An IEnumerable<T> that contains each element of the source sequence cast to the specified type.
The type to cast the elements of source to.
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.
If an element cannot be cast to type TResult, this method will throw an exception. To obtain only those elements that can be cast to type TResult, use the OfType<TResult> method instead of .
In a query expression, an explicitly typed iteration variable translates to an invocation of. This example shows the syntax for an explicitly typed range variable.
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