Expand Minimize

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

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.

The created subarray.

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

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|]

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

Silverlight

Supported in: 3

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft