Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. copy array string to by byte array

copy array string to by byte array

Scheduled Pinned Locked Moved C#
helpdata-structuresquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jeeva Jose
    wrote on last edited by
    #1

    I have a array of string .How can I place the array to byte String[] mm = {"A","B","C"}; byte[] by = new byte[3]; by = mm; This one make error How can solve this problem.

    Continue...

    G G 2 Replies Last reply
    0
    • J Jeeva Jose

      I have a array of string .How can I place the array to byte String[] mm = {"A","B","C"}; byte[] by = new byte[3]; by = mm; This one make error How can solve this problem.

      Continue...

      G Offline
      G Offline
      goyal manish
      wrote on last edited by
      #2

      Hi YOu are assigning string values to byte, thats why its giving error. You can use following code String[] mm = {"A","B","C"}; byte[] by = new byte[3]; for (int i = 0; i < mm.Length; i++) { by[i] = Convert.ToByte(mm[i]); }

      1 Reply Last reply
      0
      • J Jeeva Jose

        I have a array of string .How can I place the array to byte String[] mm = {"A","B","C"}; byte[] by = new byte[3]; by = mm; This one make error How can solve this problem.

        Continue...

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        Generally you can't convert a string to a byte. For example a string like "Hello world!" does not fit into a single byte. If you have a special case where all strings always are exactly one character long, you can get that character and get the character code for it. The character code is still 16 bits, though, while a byte only is 8 bits. To store a character code in a byte only works if the characters are all only ASCII characters, so that you can safely discard the top 8 bits of the character code.

        --- Year happy = new Year(2007);

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups