You can use Array.Resize()
, documented in MSDN.
But yeah, I agree with Corey, if you need a dynamically sized data structure, we have List
s for that.
Important: Array.Resize()
doesn't resize the array (the method name is misleading), it creates a new array and only replaces the reference you passed to the method.
An example:
var array1 = new byte[10];
var array2 = array1;
Array.Resize<byte>(ref array1, 20);
// Now:
// array1.Length is 20
// array2.Length is 10
// Two different arrays.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…