views:

223

answers:

3

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?

+1  A: 

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.

JaredPar
Thats cool, thank you for the link.
Farstucker
A: 

The major benefit of implementing your own collection class (since you are stuck in 1.1) is type safety; when you know for sure that your collection can contain only CarObj instances, there is no need for type casting or worrying about conversion errors. Internally this collection class could use an ArrayList to store the objects.

Fredrik Mörk
+4  A: 

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 :)

thecoop
WOW! U guys are fast! Thx
Farstucker