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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Apr 28, 2011, 7:02 PM
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
VulpesPosted Apr 30, 2011, 6:47 PM
> list2d = new List
>();
Richard BrennanPosted Apr 30, 2011, 6:00 PM
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).
VulpesPosted Apr 29, 2011, 4:47 AM
Richard BrennanPosted Apr 28, 2011, 7:49 PM
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?
Richard BrennanPosted Apr 28, 2011, 7:27 PM
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 BrennanPosted Apr 28, 2011, 7:19 PM