Search code examples
c#reverse

Get last bytes from byte array


I need to read last 8 bytes from byte array. Right now im doing it like this:

last8 = data.Reverse().Take(8).Reverse();

Is there any better way of doing this?


Solution

  • Use Array.Copy for example:

    byte[] data = ...;
    byte[] last8 = new byte[8];
    Array.Copy(data, data.Length-8, last8, 0, 8);