Table of contents
TOC
Collapse the table of content
Expand the table of content

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

Den Delimarsky|Last Updated: 8/18/2017
|
1 Contributor

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)

Syntax

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

// Usage:
Seq.cast source

Parameters

source Type: System.Collections.IEnumerable

The input sequence.

Exceptions

ExceptionCondition
ArgumentNullExceptionThrown 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 System.Collections.Generic.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 System.Collections.ArrayList, where the element type is just System.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 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Collections.Seq Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2017 Microsoft