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 do is to do the same thing in F#. I have searched for how to do it and looked for it in the documentation. I think that I’m probably using the wrong search terms because I can’t find out how.
What I’ve found so far is that Array.create can be used like this:
let b = Array.create x ( new Byte() )
Is there another way to do it which is more similiar to the way it can be done in C# and Java?
I think you would want to create an uninitialized array and fill it later:
It’s the way you normally do in C#/Java, which is unidiomatic in F#. Think about it; if you forget to initialize some elements, you have to deal with
nullnightmares.In almost all cases, you can always replace the above procedure by high-order functions from Array module or array comprehension:
or
Take a look at this MSDN page; it contains useful information about using Array in F#.