How to make a collection of different data types like int, string, double, char etc under one single collection name? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
- 2

How to make a collection of different data types like int, string, double, char etc under one single collection name?

11th May 2016, 5:01 PM
poonamjeet singh
4 Antworten
+ 3
Try this: List<object> list = new List<object>();
20th May 2016, 2:57 PM
James Flanders
+ 1
U can try List<T> a_list = new List<T>() where T : Auto, Person, String
6th Jul 2016, 5:56 AM
Miroslav Mikus
Miroslav Mikus - avatar
0
James got ir right..make the elements in the collection of type object. They can hold anything
1st Jul 2016, 12:18 AM
J Arrow
- 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"
10th Oct 2016, 5:11 PM
Parth