C #: data type from one to many types

For individual use, I can use a hash or dictionary. Forexample Smith 26 years old, Brown 35 years old. It is clear. How about one? Forexample Smith attends class01, class08, class12, and Brown attends classes01, class05 and class08. What are my alternatives and what is the best choice?

+4
source share
6 answers

You can still use Dictionary , but you need to make a value type for the collection, that is: Dictionary<Person, IList<Class>> . This will allow you to keep a list of classes per person.

+9
source

You can use the list dictionary as the second type.

For example, if you have a Student class and a class, you will have

 Dictionary<Student, List<Class>> 
+4
source

You can use the type Lookup<TKey, TValue> . It works almost like a dictionary, but allows you to insert equal keys. See the MSDN article http://msdn.microsoft.com/en-us/library/bb460184.aspx for details.

+1
source

You may have a hash or dictionary with a list as its value. Example:

 var d = new Dictionary<string,List<string>> { { "Smith", new List<string> { "class01", "class08", "class12" } }, { "Brown", new List<string> { "class01", "class05", "class08" } } }; 
+1
source

you can use

 Dictionary<string, List<object>> OneToManyDictionary; 
0
source

Create entity objects defined in the Person class. They have class properties to represent various attributes and collections.

 For example (pseudo-code) Person class Age Property (int) Class Property (List) ... etc. 
0
source

All Articles