- 2
How to make a collection of different data types like int, string, double, char etc under one single collection name?
4 odpowiedzi
+ 3
Try this: List<object> list = new List<object>();
+ 1
U can try
List<T> a_list = new List<T>() where T : Auto, Person, String
0
James got ir right..make the elements in the collection of type object. They can hold anything
- 1
-Create a modal class
-Include all the required properties
-Pass this class name to the required collection
For ex:
class Person
{
public int Age {get; set;}
public string Name {get; set;}
public double Weight {get; set;}
public char Gender {get; set;}
}
List<Person> personList = new List<Person>();
Now, the collection of different datatypes is under single collection called "personList"