Seq.cast<'T> Function (F#)
Collapse the table of content
Expand the table of content

Seq.cast<'T> Function (F#)

Wraps a weakly typed System.Collections sequence as a typed sequence.

Namespace/Module Path: Microsoft.FSharp.Collections.Seq

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
Seq.cast : IEnumerable -> seq<'T>

// Usage:
Seq.cast source


Type: IEnumerable

The input sequence.




Thrown when the input sequence is null.

The result sequence.

The use of this function usually requires a type annotation. An incorrect type annotation may result in runtime type errors. Individual IEnumerator<T> values generated from the returned sequence should not be accessed concurrently.

This function is named Cast in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.

The following code demonstrates the use of Seq.cast to convert a weakly typed ArrayList, where the element type is just Object, into a sequence of int.

open System
let mutable arrayList1 = new System.Collections.ArrayList(10)
for i in 1 .. 10 do arrayList1.Add(10) |> ignore
let seqCast : seq<int> = Seq.cast arrayList1

Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2

F# Runtime

Supported in: 2.0, 4.0


Supported in: 3

Community Additions

© 2015 Microsoft