Page 1 of 1

C# Adding to an array of classes?

Posted: Thu Dec 02, 2010 3:29 am
by chanika
I have this small class and have made an array, see code below.
class clsTest
{
UInt32 m_myType = 0;
UInt64 m_DBID = 0;
String m_MyDescription = "";
}
clsTest[] myTest = new clsTest[20];
I assume 20 will be enough but what if, when the application is running, it needs extra.
My Question: Is it possible to add extra element(s) dynamically by code so I can have 21 or more?
__________________________________
khao san road

Re: C# Adding to an array of classes?

Posted: Thu Dec 02, 2010 12:51 pm
by bumpo
chanika wrote:I have this small class and have made an array, see code below.
class clsTest
{
UInt32 m_myType = 0;
UInt64 m_DBID = 0;
String m_MyDescription = "";
}
clsTest[] myTest = new clsTest[20];
I assume 20 will be enough but what if, when the application is running, it needs extra.
My Question: Is it possible to add extra element(s) dynamically by code so I can have 21 or more?
__________________________________
khao san road



You may be able to use a List or Dictionary to accomplish this rather than an array:

List<clsTest> myTest = new List<clsTest>();