开发者

Instantiate array in F#?

开发者 https://www.devze.com 2022-12-09 14:52 出处:网络
In C# I\'d write something like MyType arr = new MyType[10]; to alloc arr as array which has 10 items of type MyType.

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 (e.g. null or zero), use Array.zeroCreate:

let arr : int array = Array.zeroCreate 10

To initialise with a value, use Array.init.


You could conceivably be interested in this discussion although it is in an OCaml context.

0

精彩评论

暂无评论...
验证码 换一张
取 消