我有一堂课,AClass 课。在这个类中,我正在填写两个字典,并且我正在返回这两个字典,所以我使用Tuple<Dictionary<string, string>, Dictionary<string, string>>
了方法声明的类型:
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
只返回一本字典,我会知道如何从一本字典中获取项目到另一本字典,但在这里我有Tuple,我从未使用过它,而且我不知道如何获得这两个重新调整的值。我应该这样做吗?还有另一种方法,也许将方法声明为Dictionary< Dictionary<string, string>, Dictionary<string, string>>
?
那么,如何从 Tuple 中获取字典呢?