PDA

Click to See Complete Forum and Search --> : [RESOLVED] [1.0/1.1] ArrayList<Class> vs ArrayList<String>


Jumpercables
Jan 13th, 2007, 01:42 AM
I was just curious if I should even bother with creating a new class to hold 2 parameters of information or just hold them in an array list.
Currently I am sorting information into any arraylist like the following.


ArrayList _route = new ArrayList();

_route.Add(1 + "|" + 2);
_route.Add(5 + "|" + 24);
_route.Add(123 + "|" + 12);
// etc...


Would it be "better" to use a class or structure and add it to the ArrayList, I only ask because it would reduce extra parsing when extracting the information but MOST importantly would it hinder the performance?



public class Path
{
private Int32 _clid, _oid;

public Path(Int32 CLID, Int32 OID)
{
this._clid = CLID;
this._oid = OID;
}

public Int32 CLID
{
get { return _clid; }
}

public Int32 OID
{
get { return _oid; }
}
}

// Add information to arraylist using the path class.

ArrayList _route = new ArrayList();

_route.Add(new Path(1, 2));
_route.Add(new Path(5, 24));
_route.Add(new Path(123,12));
// etc...


The Path class could be instantiated up to 100+ times.

Any ideas or thoughts would be great.

jmcilhinney
Jan 13th, 2007, 03:48 AM
You should declare a structure rather than a class, but a specific type is definitely in order.

Jumpercables
Jan 13th, 2007, 12:42 PM
That's what I expected.

penagate
Jan 14th, 2007, 11:12 PM
I would expect performance to be exactly the same, since you're using 1.1 and there are no generics.

With a generic List<Path> in 2.0 the performance would definitely be faster.

Jumpercables
Jan 15th, 2007, 09:44 PM
I did have some time today to run a time test and using a structure is faster than that just the string append so going to use a structure.


I wish I could use generics :P