Export (0) Print
Expand All
Expand Minimize

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

source

Type: IEnumerable

The input sequence.

Exception

Condition

ArgumentNullException

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 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Show:
© 2014 Microsoft