I’d like to resize an array, however I don’t want all the appended values to be zero.
Array.Resize(ref range, range.Length + grow);
If you assume that the appended length is always a multiple of 4 bytes (just enough to hold a float), what is the best way to fill this up with either float.MaxValue or float.MinValue?
Just loop through the added items and assign the value to it. The compiler will produce code to only do the range checking of the array indexes once outside the loop, so the loop will be very efficient.
You should be aware that the
Array.Resizedoesn’t actually resize the array, but it creates a new array with the desired size and copies the data from the original array. So, if you want a way to resize a collection efficiently, you shouldn’t use an array at all. Depending on your needs something like a List, a List of arrays, or a LinkedList would probably be better.