是否有任何方法清空字節數組 in C#?C#字節數組中的空元素
Byte[] array = new Byte[64]; // contain all 0
// write some value into the array
// need empty array with all 0's
是否有任何方法清空字節數組 in C#?C#字節數組中的空元素
Byte[] array = new Byte[64]; // contain all 0
// write some value into the array
// need empty array with all 0's
Byte[] array = new Byte[64];
Array.Clear(array, 0, array.Length);
使用陣列上的 「清除」 方法。
Array.Clear(array , 0, array.Length);
for (int i = 0; i < array.Length; i++)
array[i] = 0;
我試圖無休止地使用Array.Clear()來清除大的byte [],我有我的程序。它永遠不會工作。我不知道爲什麼。但我發現一個解決方案:
array = new byte [0];
謝謝!正常工作! – leon22
雖然它不會被優化出Release版本,對吧?例如:Win32中的'SecureZeroMemory'與'ZeroMemory'。 – c00000fd