Coming from C++, it's very weird to find that C# ArrayList
doesn't have Resize(count)
method?
Why? Am I missing something?
There are three separate operations you might wish to perform:
Changing the capacity of the ArrayList
. This is achievable through ArrayList.Capacity
and List<T>.Capacity
Changing the actual count of the list by trimming some elements. This is achievable through ArrayList.RemoveRange
and List<T>.RemoveRange
.
Changing the actual count of the list by adding some elements. This is achievable through ArrayList.AddRange
and List<T>.AddRange
. (As of .NET 3.5, you can use Enumerable.Repeat
to very easily come up with a sequence of the right length.)
(I mention List<T>
as unless you're really stuck on .NET 1.1, you'd be better off using the generic collections.)
If you want to perform some other operation, please specify it. Personally I'm glad that these three operations are separate. I can't think of any cases in my own experience where I've wanted to add or remove elements without knowing which I'd actually be doing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With