Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8118911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:38:34+00:00 2026-06-06T04:38:34+00:00

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

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:38:36+00:00Added an answer on June 6, 2026 at 4:38 am

    I think you would want to create an uninitialized array and fill it later:

    let arr = Array.zeroCreate 10
    for i in 0..9 do
       arr.[i] <- byte(i*i)
    

    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 null nightmares.

    In almost all cases, you can always replace the above procedure by high-order functions from Array module or array comprehension:

    let arr = Array.init 10 (fun i -> byte(i*i))
    

    or

    let arr = [| for i in 0..9 do -> byte(i*i)|]
    

    Take a look at this MSDN page; it contains useful information about using Array in F#.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a byte array that can be of size 2,3 or 4. I
I have this method in my java code which returns byte array for given
How can I represent a byte array (like in Java with byte[]) in Python?
In Java, I can't take a byte array of unsigned bytes (from something such
I have a byte array, received from java application via network. I need to
I just wrote this code to convert a GUID into a byte array. Can
Using Java, I have a class which retrieves a webpage as a byte array.
Possible Duplicate: how to convert image to byte array in java? Hi, Can anybody
How can I convert a short (2 bytes) to a byte array in Java,
I want to write a byte array to file. This is code in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.