[英]How to reverse the order of a byte array in c#?
你如何颠倒c#中字节数组的顺序?
You could use the Array.Reverse
method: 您可以使用
Array.Reverse
方法:
byte[] bytes = GetTheBytes();
Array.Reverse(bytes, 0, bytes.Length);
Or, you could always use LINQ and do: 或者,您可以始终使用LINQ并执行:
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. 你可以使用linq方法 :
MyBytes.Reverse()
以及Array.Reverse()
方法。 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. 要注意的主要事情是linq版本不会改变您的原始版本。 the Array version will change your original array.
Array版本将更改您的原始数组。
您可以使用Array.Reverse()
方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.