none
Byte array into an array of int

Answers

  • You could use the CopyTo() method:

    byte[] bites = new byte[] { 1, 2 };
    int[] intArr = new int[bites.Length];
    bites.CopyTo(intArr, 0);
    

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    • Proposed as answer by RohitArora Thursday, April 6, 2017 3:47 AM
    • Marked as answer by lctk Wednesday, April 12, 2017 12:19 AM
    Thursday, April 6, 2017 1:11 AM
    Moderator
  • Hi lctk,

    Thank you for posting here.

    For your question, you could try the following code.

     //The bytes is your byte array.
                int[] bytesAsInt1 = bytes.Select(x => (int)x).ToArray();
     int[] bytesAsInt2 = Array.ConvertAll(bytes, c => (int)c);

    I hope this would be helpful.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 6, 2017 6:29 AM
    Moderator

All replies

  • You could use the CopyTo() method:

    byte[] bites = new byte[] { 1, 2 };
    int[] intArr = new int[bites.Length];
    bites.CopyTo(intArr, 0);
    

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    • Proposed as answer by RohitArora Thursday, April 6, 2017 3:47 AM
    • Marked as answer by lctk Wednesday, April 12, 2017 12:19 AM
    Thursday, April 6, 2017 1:11 AM
    Moderator
  • Hi lctk,

    Thank you for posting here.

    For your question, you could try the following code.

     //The bytes is your byte array.
                int[] bytesAsInt1 = bytes.Select(x => (int)x).ToArray();
     int[] bytesAsInt2 = Array.ConvertAll(bytes, c => (int)c);

    I hope this would be helpful.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 6, 2017 6:29 AM
    Moderator