Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

c#

arraylist

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.

like image 914
user1172468 Avatar asked Aug 09 '26 22:08

user1172468


1 Answers

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.

like image 73
Habib Avatar answered Aug 11 '26 13:08

Habib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!