1
看起來我永遠不會遇到問題。現在我想初始化這樣的解釋(正是這一點):我如何創建一個真正複雜的集合?
Dictionary<string, Dictionary<int, int>> origRes = new Dictionary<string, Dictionary<int, int>>
不然我需要一個集合,它可以包含一個字符串和兩個整數值。並且將足夠簡單的for
或foreach
循環來收集所有這些數據(該字符串可以是一個關鍵值)?
更新
public static Dictionary<int, int> resRequest(string requestedForm)
{
Dictionary<int, int> kp = new Dictionary<int, int>();
Dictionary<string, KeyValuePair<int, int>> origRes = new Dictionary<string, KeyValuePair<int, int>>();
origRes.Add("Polübiosz", new KeyValuePair<int, int>(560,310));
origRes.Add("Morze", new KeyValuePair<int, int>(690, 510));
origRes.Add("Caesar", new KeyValuePair<int, int>(700, 500));
origRes.Add("OwnCrypt", new KeyValuePair<int, int>(830, 570));
origRes.Add("Hamming", new KeyValuePair<int, int>(850, 500));
origRes.Add("Kezdőkép", new KeyValuePair<int, int>(1280, 1024));
foreach(KeyValuePair<string,KeyValuePair<int, int>> pair in origRes)
{
if(pair.Key==requestedForm)
{
kp.Add(pair.Value.Key,pair.Value.Value);
}
}
return kp;
}
這裏是我完整的方法,我想拿到鑰匙,並從KeyValuePair
值,但返回的字典不包含它或我不知道,但在調用方沒有鍵或值屬性只有鍵和值。