- Home /
Question by
Alanimator · Oct 14, 2013 at 02:46 PM ·
c#stringdictionaryvalueskeys
How do I create a Key and Values Dictionary array in C#
I have created dictionaries before but in vb.net where i would do this
Private degreeDictionary As Dictionary(Of String, String())
Public Sub kanjsort()
degreeDictionary= New Dictionary(Of String, String())
degreeDictionary.Add("ups", {"updegree", "popup"})
End sub
in C# a generally similar method is used
Dictionary<string, string> degreeDictionary= new Dictionary<string,string>();
Void Start ()
{
degreeDictionary.add("upps","updata","goingup");
}
I have been looking around but I havent seen any references to keys and values array type dictionary .
how can I create an array dictionaty that can hold keys and values in this manner degreeDictionary.Add("ups", {"updegree", "popup"})..... or something like this
Comment
Best Answer
Answer by Ejlersen · Oct 14, 2013 at 07:30 PM
You would probably have to do something like this:
Dictionary<string, List<string>> degreeDictionary = new Dictionary<string List<string>>();
void Start()
{
string key = "ups";
List<string> value = new List<string>();
value.Add("updegree");
value.Add("popup");
degreeDictionary.Add(key, value);
}
Or:
Dictionary<string, string[]> degreeDictionary = new Dictionary<string string[]>();
void Start()
{
degreeDictionary.Add("ups", new string[2] { "updegree", "popup" });
}