Copy byte array to another byte array in C#

后端 未结 2 481
再見小時候
再見小時候 2020-12-18 17:52

There are two byte arrays which are populated with different values.

byte[] Array1 = new byte[5];
byte[] Array2 = new byte[5];

Then, I need

相关标签:
2条回答
  • 2020-12-18 18:46
    Array1.CopyTo(Array2, 0);
    

    MSDN

    0 讨论(0)
  • 2020-12-18 18:50

    One solution courtesy of Linq...

    Array1 = Array2.ToArray();
    

    EDIT: you do not need to allocate space for Array1 before using this Linq call. The allocation for Array1 is done within ToArray(). More complete example below

    byte[] Array2 = new byte[5];
    // set values for Array2
    byte[] Array1 = Array2.ToArray();
    
    0 讨论(0)
提交回复
热议问题