How do you reverse the order of a byte array in c#?
Asked
Active
Viewed 6.6k times
5 Answers
53
You could use the Array.Reverse
method:
byte[] bytes = GetTheBytes();
Array.Reverse(bytes, 0, bytes.Length);
Or, you could always use LINQ and do:
byte[] bytes = GetTheBytes();
byte[] reversed = bytes.Reverse().ToArray();

Harry Steinhilber
- 5,219
- 1
- 25
- 23
8
you can use the linq method: MyBytes.Reverse()
as well as the Array.Reverse()
method.
Which one you should use depends on your needs.
The main thing to be aware of is that the linq version will NOT change your original. the Array version will change your original array.

Muad'Dib
- 28,542
- 5
- 55
- 68
2
You can use the Array.Reverse()
method.

rink.attendant.6
- 44,500
- 61
- 101
- 156

Bala R
- 107,317
- 23
- 199
- 210
2
You can use Array.Reverse. Also please go through this for more information.

Community
- 1
- 1

Shankar Raju
- 4,356
- 6
- 33
- 52