简体   繁体   中英

Instantiate array in F#?

In C# I'd write something like

MyType arr = new MyType[10];

to alloc arr as array which has 10 items of type MyType .

How to do the same in F# ??

let mutable arr = ?????????????

To initialise the array to the default (eg null or zero), use Array.zeroCreate:

let arr : int array = Array.zeroCreate 10

To initialise with a value, use Array.init.

您可能会对此讨论感兴趣,尽管它是在OCaml上下文中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM