bytes in C#

Discussion in 'C#' started by joecole, Oct 7, 2008.

  1. joecole

    joecole New Member

    Joined:
    Sep 10, 2008
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Code:
     
                Console.WriteLine(sizeof(long));
                
                long a = long.MaxValue;
                byte[] tmp = ASCIIEncoding.ASCII.GetBytes(a.ToString());
                foreach (byte item in tmp2)
                {
                    Console.Write(item + "; ");
                } 
    Please help me:
    sizeof(long) is 8, but why does tmp have more than 8 elements.
     
  2. Bitmatic

    Bitmatic New Member

    Joined:
    Nov 2, 2008
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.bitmatic.com
    Because the number in "a" has 19 digits.

    a.ToString() returns a string that is 19 bytes long, so tmp becomes 19 elements long too.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice