开发者

Empty elements in C# byte array

Is there any method to empty an Byte array in C#?

Byte[] array = new Byte[64]; // contain all 0

// write some value into the arra开发者_JAVA百科y

// need empty array with all 0's


Byte[] array = new Byte[64];

Array.Clear(array, 0, array.Length);


Kindly use Array.Empty method

byte[] rawBytes = Array.Empty();


I tried endlessly to use Array.Clear() to clear a large byte[] that I have in my program. It would NEVER work. I do not know why. But I found a solution:

array = new byte[0];


Use the "clear" method on Array.

 Array.Clear(array , 0, array.Length);


for (int i = 0; i < array.Length; i++)
    array[i] = 0;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜