Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use an ArrayList or IList

Im using the .NET framework 1.1 and Im hoping someone could help me implement a dynamic array of objects?

A watered-down example of the object I wish use is below.

Class CarObj
{
   public string CarName;
   public string CarYear;
}

Should I use an ArrayList or do you think it would be better to make a CarList class to implement an IList interface? Is there a performance benefit for one over another?

like image 338
Ryan Avatar asked Mar 18 '10 20:03

Ryan


2 Answers

If you are using 1.1 and need a dynamic array style collection then ArrayList is the best choice to get you moving.

I do hate all of the casting that comes with using ArrayList though and I certainly don't fault people for writing custom collections that have strongly implemented members in 1.1. However if you do go this route I would suggest using a custom generator vs. tedious hand coding. There are several available that can quickly be found via google

This link for example will actually generate the code for you on the website and it can be simply copy and pasted into your project.

  • http://www.aspnetemail.com/free/collectionGen.aspx
like image 20
JaredPar Avatar answered Sep 30 '22 09:09

JaredPar


Inherit CollectionBase instead; this wraps IList and allows you to provide your own implementation of typed methods you need. This is what it's designed for :)

like image 54
thecoop Avatar answered Sep 30 '22 07:09

thecoop