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 Cast<(Of <(TResult>)>)(IEnumerable) method enables the standard query operators to be invoked on non-generic collections by supplying the necessary type information. For example, ArrayList does not implement IEnumerable<(Of <(T>)>), but by calling Cast<(Of <(TResult>)>)(IEnumerable) on the ArrayList object, the standard query operators can then be used to query the sequence.
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<(Of <(TResult>)>) method instead of Cast<(Of <(TResult>)>)(IEnumerable).
In a query expression, an explicitly typed iteration variable translates to an invocation of Cast<(Of <(TResult>)>)(IEnumerable). This example shows the syntax for an explicitly typed range variable.
From i As Integer In objects