我有一個類,類AClass。在這個類中,我灌兩本詞典還,我要回這兩個字典所以我用Tuple<Dictionary<string, string>, Dictionary<string, string>>
型方法聲明:從另一個類中的一種方法返回兩個字典與Tuple
class AClass
{
Dictionary<string, string> dictOne = new Dictionary<string, string>();
Dictionary<string, string> dictTwo = new Dictionary<string, string>();
public Tuple<Dictionary<string, string>, Dictionary<string, string>> MyMethodOne()
{
//Adding items dictOne and dictTwo
return new Tuple<Dictionary<string, string>, Dictionary<string, string>>(dictOne, dictTwo);
}
}
在其他階級,階層BClass,我應該得到這些兩個詞典,訪問並添加自己的物品到另外兩個字典:
class BClass
{
AClass _ac = new AClass();
Dictionary<string, string> dictThree = new Dictionary<string, string>();
Dictionary<string, string> dictFour = new Dictionary<string, string>();
public void MyMethodTwo()
{
//Here I should get dictionaries through Tuple
//Add items from dictOne to dictThree
//Add items from dictTwo to dictFour
//In a way
// foreach (var v in accessedDict)
// {
// dictThree.Add(v.Key, v.Value);
// }
}
}
如果MyMethodOne
是隻返回一個字典我會知道如何從一個詞典項目的方式,但在這裏我有元組,與whic我從來沒有工作過,我不知道如何得到這兩個重新調整的價值觀。我應該這樣做嗎?有沒有另一種方法,也許宣佈方法爲Dictionary< Dictionary<string, string>, Dictionary<string, string>>
?
那麼,如何從Tuple中獲得字典呢?
請閱讀此http://msdn.microsoft.com/en-us/library/dd268536.aspx。 – juharr
@juharr感謝之手 – Sylca