- Home /
 
 
               Question by 
               Clawiste · Aug 09, 2014 at 10:33 AM · 
                c#listdictionary  
              
 
              Can be list stored in dictionary?
Hello,
The title explains if. Can it be done? If so, then how?
Currently I have this setup
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
         
 public class GameGeneration : MonoBehaviour {
         
     // Setup Dictionary for list
     Dictionary<string, List<ModularGameObjects>()> lists = new Dictionary<string, List<ModularGameObjects>()>();
         
     void Awake() {
         // Add stuff to list
         lists.Add ("Platform", new List<ModularGameObjects>());
         lists.Add ("Wall", new List<ModularGameObjects>());
         lists.Add ("Stair", new List<ModularGameObjects>());
     }
 }
 
              
               Comment
              
 
               
              I'm curious. Did you even bother searching? What search engine/terms did you use?
 
               Best Answer 
              
 
              Answer by Ekta-Mehta-D · Aug 09, 2014 at 12:17 PM
I think Its possible. you can refer this link :
http://stackoverflow.com/questions/5037997/dictionary-of-generic-lists-or-varying-types
Doing this
 Dictionary<string, IList> lists = new Dictionary<string, IList>();
 
                  ins$$anonymous$$d of this
 Dictionary<string, List<$$anonymous$$odularGameObjects>()> lists = new Dictionary<string, List<$$anonymous$$odularGameObjects>()>();
 
                  helped, Thanks.
No need to use the IList, just do:
     Dictionary<string, List<$$anonymous$$odularGameObjects>> lists = new Dictionary<string, List<$$anonymous$$odularGameObjects>>();
 
                  Now it's a strong typed dictionary that contains a strong typed list.
Your answer
 
             Follow this Question
Related Questions
Sorting a List of Dictionaries in C#? 4 Answers
A node in a childnode? 1 Answer
Runtime instantiation based on XML 1 Answer
IDictionary 1 Answer
How to send/copy array from dictionary to class and further to list of class 0 Answers