1
我想擴大我的字典用法,並希望爲我的對有多個值。C#元組詞典
我對添加項目到字典沒有任何問題。 我試圖使用Tuple作爲選項,但似乎無法弄清楚如何提取特定的值。
這個工程:
Dictionary<string, string> voc4 = new Dictionary<string, string>();
voc1.Add(key1, value);
if (voc1.TryGetValue(result.Text.ToLower(), out string cmd))
{
ToSend(cmd);
}
我試圖建立與元組新的辭典:
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
}
我怎樣才能得到一定的價值基礎上的密鑰,並用他們不同的功能? 例子是:
if (voc5.TryGetValue(result.Text.ToLower(), out string cmd))// the first value
{
ToSend(value 1 from tuple).ToString();
ToDisplay(value 2 from tuple).ToString();
}
任何幫助將是巨大的
不是沒有,但你問了7個問題,並得到10個答案,但沒有一個答案被接受。接受答案表示回答的問題(「已解決」)。隨着投票,它還可以幫助其他用戶找到好的答案/帖子。即使您無法發佈答案,也可以幫助他人。 [旅遊]用約2分鐘的圖片解釋它 – Plutonix
我很抱歉。我不知道該如何解決和幫助。 –
而不是'out string cmd'(甚至編譯?)它應該是'out Tuple tuple',因爲這是'voc5'字典中的值類型。 –
Dialecticus