How to reverse the order of a byte array in c#?

How do you reverse the order of a byte array in c#?

5 Answers

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();
Array.Reverse(byteArray);

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.

You can use Array.Reverse. Also please go through this for more information.

You can use the Array.Reverse() method.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like