I am trying to expand my usage of the dictionary and want to have multiple values for my pairs.
I have had no issues with adding items to the dictionary with one . I have tried to use Tuple as an option but cant seem to figure out how to extract a particular value.
this works:
Dictionary<string, string> voc4 = new Dictionary<string, string>(); voc1.Add(key1, value); if (voc1.TryGetValue(result.Text.ToLower(), out string cmd)) { ToSend(cmd); } I tried to build a new dictionary with Tuple:
Dictionary<string, Tuple<string ,string>> voc5 = new Dictionary<string,Tuple<string ,string>>(); voc5.Add(key1, new Tuple<string, string>(value,response)); if (voc5.TryGetValue(result.Text.ToLower(), out string cmd)) {//this is what I cant get working. I want to get the first value of thedictionary for 1 purpose and the other for a different purpose } How can I get certain values based on the key and use them for different functions? example would be:
if (voc5.TryGetValue(result.Text.ToLower(), out string cmd))// the first value { ToSend(value 1 from tuple).ToString(); ToDisplay(value 2 from tuple).ToString(); } Any help would be great
out string cmd(does that even compile?) it should beout Tuple<string, string> tuple, because that is the value type invoc5dictionary.