Expand Minimize

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

Creates an array given the dimension and a generator function to compute the elements.

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

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

// Signature:
Array.init : int -> (int -> 'T) -> 'T []

// Usage:
Array.init count initializer

count

Type: int

The number of elements to initialize.

initializer

Type: int -> 'T

The function to generate the initial values for each index.

The created array.

This function is named Initialize 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 Array.init.


printfn "Array of squares: %A" (Array.init 10 (fun index -> index * index))


Array of squares: [|0; 1; 4; 9; 16; 25; 36; 49; 64; 81|]

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

Silverlight

Supported in: 3

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

Community Additions

ADD
Show:
© 2014 Microsoft