私は 2 つの辞書を返そうとしましたが、成功しましたが、遅いので満足できません。Tuple でこれまでに行ったことは次のとおりです。別のクラス内の 1 つのメソッドから Tuple を使用して 2 つの辞書を返す
Tupla が遅いという私の声明を裏付けるベンチマークもここにあります: http://www.dotnetperls.com/multiple-return-values
Returning two dictionaries with Tuple from one method within another classから同じ状況を考慮して、Tupla の代わりに KeyValuePair 宣言を使用しようとしましたが、次のエラーが発生します。
タイプ '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
}
}
残念ながら、これは「トゥプラ方式」以外の方法ではできないということです。
助言がありますか?