Im writing a class library and i want it to handle any type of data.
Q1: do I decelare data members as
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Apr 28, 2011, 3:02 PM EDT
List
list.Add(1);
list.Add(42);
int count = list.Count; // 2
You can declare a generic List of any type you like - even object.
List
list2.Add("hello"); // add a string
list2.Add(23.5); // add a double
list2.Add(list); // add a List
int count2 = list2.Count; // 3
Richard Brennan89 reputationPosted Apr 28, 2011, 3:19 PM EDT
Richard Brennan89 reputationPosted Apr 28, 2011, 3:27 PM EDT
1) one constructor to set the list to null
2) could i user constructor(params object varName) and us this to pass an array of data to put in the list. (could i use varNAme.length to count the elements of varNAme?
Richard Brennan89 reputationPosted Apr 28, 2011, 3:49 PM EDT
If i do: myList.RemoeAt(2) //delete an item
does all the data in postion 3+ automatically move 1 place left to fill the space or do i have to handle that my self?
VulpesRank #55 · 29.2K reputationPosted Apr 29, 2011, 12:47 AM EDT
Richard Brennan89 reputationPosted Apr 30, 2011, 2:00 PM EDT
Is this possible
List
for(int i = 0; i < 10; i++)
{
List
myList.Add(newList);
}
woule the newList decleration give the compiler a wobbly. Does each decleartion need a new name - and if so how do u assign the names.
Again it is unknown at design time how long the list of lists may need to be.
I suppose this is similar to a matrix - how can u declare an undimensioned matrix (where each row [or column] can be different lengths).
VulpesRank #55 · 29.2K reputationPosted Apr 30, 2011, 2:47 PM EDT
> list2d = new List
>();