locked
Why we use Byte[] instead of String[]? RRS feed

  • Question

  • User-663248805 posted

    I have seen many example where people user Byte[] array instead of String[]

     any reason for that?

    Monday, March 2, 2009 4:20 AM

Answers

  • User377791177 posted

    1. if we don't use byte[] , how can we get say for e.g. the contents of a .jpg file in string [*-)]

     

    2. A string itself is an array of character, what if i want to take the first character's 4th bit in string "abc".

     

    3. notepad opens everything in string only, can u open ms-excel file in notepad?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 2, 2009 4:33 AM
  • User-690506545 posted

    Probably for the same reason that people will use:

    int[] for an array of ints

    decimal[] for an array of decimals

    string[] for an array of strings

    byte[] for an array of bytes.

    If you rephrase the question:

    "I have seen many example where people user Byte instead of String"

    It makes it obvious why.

    [:)]

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 2, 2009 4:42 AM

All replies

  • User377791177 posted

    1. if we don't use byte[] , how can we get say for e.g. the contents of a .jpg file in string [*-)]

     

    2. A string itself is an array of character, what if i want to take the first character's 4th bit in string "abc".

     

    3. notepad opens everything in string only, can u open ms-excel file in notepad?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 2, 2009 4:33 AM
  • User97111691 posted

    http://www.codeverge.net/ng.asp-net-forum.getting_started/what-the-difference-between-byte-array-and-string

    Monday, March 2, 2009 4:36 AM
  • User1284226139 posted

    Each byte can store ascii code from 0 to 255, so you can store 0 ,0 ,0 ,0, 'A','B','C','D' etc...

    String has a terminated character to let end the string most of the language use 0 to end the string e.g( c,c++, etc..)

    so programmer fill better to use byte when they are storing / sending fixed numbers of bytes with null character like socket programming.

     

    Monday, March 2, 2009 4:38 AM
  • User-690506545 posted

    Probably for the same reason that people will use:

    int[] for an array of ints

    decimal[] for an array of decimals

    string[] for an array of strings

    byte[] for an array of bytes.

    If you rephrase the question:

    "I have seen many example where people user Byte instead of String"

    It makes it obvious why.

    [:)]

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 2, 2009 4:42 AM