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
Parameters
count
Type: intThe number of elements to initialize.
initializer
Type: int -> 'TThe function to generate the initial values for each index.
Return Value
The created array.
Remarks
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.
Example
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|]
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
Silverlight
Supported in: 3