Declaring a arrays of objects dynamically
-
-
Hi all, I need to create arrays of object dynamically. for example class Pesron; Person[] p=new Person[10]; it creates 10 objects ob type person. I don't know the exact number of objects. i have to specify it in run time Thanks n Regards, Ramya.R
-
Hi all, I need to create arrays of object dynamically. for example class Pesron; Person[] p=new Person[10]; it creates 10 objects ob type person. I don't know the exact number of objects. i have to specify it in run time Thanks n Regards, Ramya.R
Hello Ramya, Do you know link list data structure. It will allow you to insert any number of object.
Divyang Mithaiwala System Engineer & Software Developer
-
Hi all, I need to create arrays of object dynamically. for example class Pesron; Person[] p=new Person[10]; it creates 10 objects ob type person. I don't know the exact number of objects. i have to specify it in run time Thanks n Regards, Ramya.R
-
Hi all, I need to create arrays of object dynamically. for example class Pesron; Person[] p=new Person[10]; it creates 10 objects ob type person. I don't know the exact number of objects. i have to specify it in run time Thanks n Regards, Ramya.R
A few others have replied here saying to use ArrayList. That is fine. If you're using .NET 2.0, you can use the System.Collections.Generic.List object to store your Person objects in a strongly-typed fashion (which ArrayList will not do). For example:
using System.Collections.Generic;
...
List< Person > persons = new List< Person >();
persons.Add(somePerson);
persons.Add(5); // compile-time error: persons can only contain Person objects. This is something ArrayList will NOT give you, hence the benefit of using List-- modified at 10:39 Wednesday 8th March, 2006
-
Hello Ramya, Do you know link list data structure. It will allow you to insert any number of object.
Divyang Mithaiwala System Engineer & Software Developer
-
A few others have replied here saying to use ArrayList. That is fine. If you're using .NET 2.0, you can use the System.Collections.Generic.List object to store your Person objects in a strongly-typed fashion (which ArrayList will not do). For example:
using System.Collections.Generic;
...
List< Person > persons = new List< Person >();
persons.Add(somePerson);
persons.Add(5); // compile-time error: persons can only contain Person objects. This is something ArrayList will NOT give you, hence the benefit of using List-- modified at 10:39 Wednesday 8th March, 2006
-
Can i use the link list concept in C#.It needs pointer to denote address.. Thanks n Regards, Ramya.R
Do you know that when u declare any object it will just declare reference not allocate memory for that. Now you can use this concept for link list.
Divyang Mithaiwala System Engineer & Software Developer
-
Do you know that when u declare any object it will just declare reference not allocate memory for that. Now you can use this concept for link list.
Divyang Mithaiwala System Engineer & Software Developer