J
Jack Addington
Quite new to C# but I am getting quite confused with Array's and ArrayLists.
This is probably the same old iteration of a basic question but I can't seem
to find a clear answer/example of this case.
Basically I want a container that points to a set objects that I can then
interate through to group together a set of methods in a transaction. The
number of objects is unknown at compile time. I can't seem to come up with
a dynamic array of object references... only copies. I don't want 2
versions of the object. I'm getting confused between ArrayList and the need
to dynamically re-allocate the array each time I need to add a new object.
-------------
ie) object A = new object();
object B = new object();
object C = new object();
object[] list;
then how do I increase the size of the array so I can do:
object[1] = &A;
object[2] = &B;
object[3] = &C;
then my goal is to do
foreach( object l in list )
l.Save( )
---------------
Am I missing something with ArrayList? It isn't clear to me that
ArrayList.Add( object ) doesn't create another copy...
thx
This is probably the same old iteration of a basic question but I can't seem
to find a clear answer/example of this case.
Basically I want a container that points to a set objects that I can then
interate through to group together a set of methods in a transaction. The
number of objects is unknown at compile time. I can't seem to come up with
a dynamic array of object references... only copies. I don't want 2
versions of the object. I'm getting confused between ArrayList and the need
to dynamically re-allocate the array each time I need to add a new object.
-------------
ie) object A = new object();
object B = new object();
object C = new object();
object[] list;
then how do I increase the size of the array so I can do:
object[1] = &A;
object[2] = &B;
object[3] = &C;
then my goal is to do
foreach( object l in list )
l.Save( )
---------------
Am I missing something with ArrayList? It isn't clear to me that
ArrayList.Add( object ) doesn't create another copy...
thx