Coming from C++, it’s very weird to find that C# ArrayList doesn’t have Resize(count) method?
Why? Am I missing something?
Coming from C++, it’s very weird to find that C# ArrayList doesn’t have Resize(count)
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are three separate operations you might wish to perform:
Changing the capacity of the
ArrayList. This is achievable throughArrayList.CapacityandList<T>.CapacityChanging the actual count of the list by trimming some elements. This is achievable through
ArrayList.RemoveRangeandList<T>.RemoveRange.Changing the actual count of the list by adding some elements. This is achievable through
ArrayList.AddRangeandList<T>.AddRange. (As of .NET 3.5, you can useEnumerable.Repeatto 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.