C# Adding to an array of classes?

C# discussion

Moderator: moderators

chanika
rank: <50 posts
rank: <50 posts
Posts: 23
Joined: Mon Nov 22, 2010 5:44 am
Reputation: 0
Gender: None specified

C# Adding to an array of classes?

Postby chanika » Thu Dec 02, 2010 3:29 am

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

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.

bumpo
rank: <50 posts
rank: <50 posts
Posts: 9
Joined: Tue Aug 18, 2009 2:08 pm
Reputation: 2
Gender: Male

Re: C# Adding to an array of classes?

Postby bumpo » Thu Dec 02, 2010 12:51 pm

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>();


Return to “C# coding for NeoTicker”