Custom class and ArrayList

S

Steven Blair

Hi,

I want to know if this is the most efficient method of fixing my
problem:

I have a custom class and I need to maintain an array of these items.
Initially I used MyCustom[] a = new MyCustom[someSize];

However, a new requirement has popped up which means this array might
change size (adding elements only) so I need to add more MyCustom clases
to my structure.
Having a "ReDim" method is far too slow, so my thinking is an ArrayList
would be the best array object:

ArrayList a = new ArrayList();

a.Add( new MyCustom() );

MyCustom handle = (MyCustom)a;

Anyone see any problems with this (performance is very important)

Thanks for the help in advance.

Steven
 
B

Bill B

Consider using a strongly-typed List instance. Search MSDN on "List<T>
class" for more info:

MyCustom inst1 = new MyCustom();
MyCustom inst2 = new MyCustom();

List<MyCustom> arrCustom = new List<MyCustom>();
properties.Add(inst1);
properties.Add(inst2);

foreach(MyCustom inst in arrCustom)
{
// do stuff
}

Bill
 
B

Bill Block

Consider using a strongly-typed List instance. Search MSDN on "List<T>
class" for more info:

MyCustom inst1 = new MyCustom();
MyCustom inst2 = new MyCustom();

List<MyCustom> arrCustom = new List<MyCustom>();
properties.Add(inst1);
properties.Add(inst2);

foreach(MyCustom inst in arrCustom)
{
// do stuff
}

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top