Share via


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

Parameters

Exceptions

Exception

Condition

ArgumentNullException

Thrown when the input sequence is null.

Return Value

The result sequence.

Remarks

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.

Example

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

Platforms

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

Version Information

F# Runtime

Supported in: 2.0, 4.0

Silverlight

Supported in: 3

See Also

Reference

Collections.Seq Module (F#)

Microsoft.FSharp.Collections Namespace (F#)