我试图返回两本词典并成功,但我对它不满意,因为它很慢。以下是我迄今为止对 Tupla 所做的:从另一个类中的一个方法返回两个带有 Tuple 的字典
这也是支持我关于 Tupla 很慢的声明的基准:http: //www.dotnetperls.com/multiple-return-values
考虑到从另一个类中的一个方法返回两个具有元组的字典的相同情况,我尝试使用 KeyValuePair 声明而不是 Tupla,但我收到此错误:
无法将类型“System.Tuple,System.Collections.Generic.Dictionary>”隐式转换为“System.Collections.Generic.KeyValuePair,System.Collections.Generic.Dictionary>”
这是代码:
class AClass
{
Dictionary<string, string> dictOne = new Dictionary<string, string>();
Dictionary<string, string> dictTwo = new Dictionary<string, string>();
public KeyValuePair<Dictionary<string, string>, Dictionary<string, string>> MyMethodOne()
{
//Adding items dictOne and dictTwo
return new KeyValuePair<Dictionary<string, string>, Dictionary<string, string>>(dictOne, dictTwo);
}
}
和
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 get mentioned error
KeyValuePair<Dictionary<string, string>, Dictionary<string, string>> calledKVP = _ac.MyMethodOne();
Dictionary<string, string> dictThree = calledKVP.Key;
Dictionary<string, string> dictFour = calledKVP.Value;
//After this I loop through dictThree and dictFour and do what I need
}
}
恐怕这意味着它不能以“图普拉方式”的其他方式完成。
有什么建议么?