Array.sub<'T> Function (F#)

Builds a new array that contains the given subrange specified by starting index and length.

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

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

// Signature:
Array.sub : 'T [] -> int -> int -> 'T []

// Usage:
Array.sub array startIndex count

Parameters

  • array
    Type: 'T[]

    The input array.

  • startIndex
    Type: int

    The index of the first element of the subarray.

  • count
    Type: int

    The length of the subarray.

Return Value

The created subarray.

Remarks

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

Example

The following example shows the use of Array.sub to specify a subarray. The output shows that the subarray starts at a zero-based index of 5 and has 10 elements.

let a1 = [| 0 .. 99 |]
let a2 = Array.sub a1 5 10
printfn "%A" a2
[|5; 6; 7; 8; 9; 10; 11; 12; 13; 14|]

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

Reference

Collections.Array Module (F#)

Microsoft.FSharp.Collections Namespace (F#)