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

  • Home
  • SEARCH
  • 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 9154141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:22:58+00:00 2026-06-17T12:22:58+00:00

I feel like I’m taking 2 steps back with this question, but something is

  • 0

I feel like I’m taking 2 steps back with this question, but something is confusing me a little. I’m working with some communication via TCP/IP and byte[]’s.

So I start building my byte[] array, and the third byte requires the length of the byte[]. If I declare my byte like so;

byte[] bytesToSend = new byte[119];

and then fill in the first three bytes with data..

bytesToSend[0] = 0x40;
bytesToSend[1] = 0x40;
bytesToSend[2] = Encoding.ASCII.GetBytes(bytesToSend.Length.ToString())[0];

and finally just print out the third byte, which should contain the length;

MessageBox.Show(BitConverter.ToString(bytesToSend));

should I be expecting it to return the byte size of 119, or is this just the maximum size? Currently it’s returning hex “0x31”, which as far as i’m aware doesn’t equal 119 or 3. This is no doubt something simple / fundamental I’m missing, but could someone point me in the right direction?

  • 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-17T12:22:58+00:00Added an answer on June 17, 2026 at 12:22 pm

    Seems you are unclear on what you are actually doing here:

    bytesToSend[2] = Encoding.ASCII.GetBytes(bytesToSend.Length.ToString())[0];
    

    Let’s break this line down:

    bytesToSend.Length 
    

    Returns the integer 119

    .ToString()
    

    Returns the string “119”

    Encoding.ASCII.GetBytes("119")
    

    Returns a byte array of the characters that make up the ascii string “119”.

    [0]
    

    Get just the first byte of this array, which would equal 0x31, because this is the ascii code for the character ‘1’.

    Also, there is no such thing as an actual size of a c# Array. There is only a Length. If you mean to ask how many of the elements contain non-zero bytes, that’s another story, but once you declare

    byte[] bytesToSend = new byte[119];
    

    You get a byte array with 119 elements, and it’s Length will always be 119, regardless of how many elements you have modified.

    If you need to use a collection with a more dynamic size, consider using a List<byte> instead.

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

Sidebar

Related Questions

I feel like this is a dumb question and I'm missing something, but I
I feel like such a noob asking this but, for some reason a horizontal
I feel like this is something I should already know, but I'm just not
I feel like this question has been asked before but the answers seem pretty
I feel like I'm missing something here, but I have this datagrid which when
I feel like the answer to this question is really simple, but I really
I feel like I'm missing something small, but I can't seem to make this
I feel like this is a rather simple question, but I can't seem to
I feel like this is a very noob question.. but I just can't get
I feel like this is probably a pretty simple question, but this is my

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.