简体   繁体   中英

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

你如何颠倒c#中字节数组的顺序?

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);
\n

 

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.

您可以使用Array.Reverse()方法。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM