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

前端 未结 5 659
遇见更好的自我
遇见更好的自我 2021-01-01 19:20

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

相关标签:
5条回答
  • 2021-01-01 19:26

    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.

    0 讨论(0)
  • 2021-01-01 19:32

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

    0 讨论(0)
  • 2021-01-01 19:35

    You can use the Array.Reverse() method.

    0 讨论(0)
  • 2021-01-01 19:43

    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();
    
    0 讨论(0)
  • 2021-01-01 19:50
    Array.Reverse(byteArray);
    

     

    0 讨论(0)
提交回复
热议问题