none
Get range of bytes from byte[] RRS feed

  • Question

  • Is there a preset function to get a range of bytes from a byte array? for example if my byte array had 20 bytes and I wanted the bytes from index 5 to 10 and put it into a different 5 byte array, is there a specific function or do I just make my own?

    Wednesday, July 22, 2009 1:26 PM

Answers

All replies

  • Yes there is: Array.Copy (sourceArray, 5, destinationArray, 0, 5);

    Here's the documentation .

    Regards,
    Fernando.

    I always try to Keep it Sharp & simple.
    • Marked as answer by Rehabilitated Wednesday, July 22, 2009 4:08 PM
    Wednesday, July 22, 2009 1:30 PM
  • byte[] array = new byte[] { 3, 14, 6, 99, 100, . . . };
    var selected = array.Skip(5).Take(6).ToArray();
    http://blog.voidnish.com
    • Marked as answer by Rehabilitated Wednesday, July 22, 2009 4:09 PM
    Wednesday, July 22, 2009 1:42 PM
    Moderator
  • Thanks fellas.
    • Proposed as answer by Xeev Wednesday, June 13, 2018 6:39 PM
    Wednesday, July 22, 2009 4:09 PM
  • Is there a preset function to get a range of bytes from a byte array? for example if my byte array had 20 bytes and I wanted the bytes from index 5 to 10 and put it into a different 5 byte array, is there a specific function or do I just make my own?

    arr[] source;

    arr[] result;

    Array.Copy(source, (int) startSourceIndex, result, (int) startResultIndex (set '0'), (int)length)

    this Method is best of the best =)


    • Edited by amurskiy Tuesday, August 14, 2018 10:52 AM
    Tuesday, August 14, 2018 10:50 AM