user1172468
user1172468

Reputation: 5474

Is ArrayList in C# a good equivalent for ArrayList in Java?

I'm new to C# -- under 50 lines of code in.

So the question is ArrayList in C# is a good substitute for ArrayList in Java.

Here are some differences that I've noticed:

  1. ArrayList in C# does not seem to support Generics -- this was surprising and it leads me to believe that I'm looking at an older collection class.
  2. I can't seem to be able to do an in-place replace of an element like I can in Java using set(index, value)
  3. What is more confusing is that to access element n in C# I have to use the array accessor [n] as opposed to get(n)
  4. Further thought I can access the element in c# using [] I cannot set say myarraylist[n]="bla"

So this leads me to believe that I'm missing something here - perhaps something about the C# design philosophy.

I've tried digging around the Internet for C# for Java programmers but I still do not have good answers to this question.

Upvotes: 2

Views: 1810

Answers (1)

Habib
Habib

Reputation: 223422

Use List<T> for generics, that is roughly equivalent to Java ArrayList

The List(Of T) class is the generic equivalent of the ArrayList class. It implements the IList(Of T) generic interface by using an array whose size is dynamically increased as required.

Upvotes: 12

Related Questions