Create a byte array with dynamic size in F#

前端 未结 4 1828
被撕碎了的回忆
被撕碎了的回忆 2021-02-20 07:16

In C# and Java a byte array can be created like this

byte[] b = new byte[x];

where x denotes the size of the array. What I want to

4条回答
  •  半阙折子戏
    2021-02-20 07:42

    A closest F# analog would be Array.zeroCreate:

    let b: byte [] = Array.zeroCreate x
    

    Instead of implicit array elements initialization to 0 bytes on Java and C# platforms F# makes the initial value of array elements obvious.

    As to dynamic size of b in F# it is defined once by x value at the allocation and cannot be changed later by changing x, similarly to C#/Java,.

提交回复
热议问题