私は2つの文字列を返す必要がある関数を持っています。私はKeyValuePair <>アプローチを使用したいが、私は、私は、このオブジェクトが作成された目的を悪用だと感じKeyValuePairを返すか、C#で変数を使用しますか?
string first = "this is first";
string second = "this is second";
KeyValuePair<string, string> ReturnPair()
{
return new KeyValuePair<string, string>(first, second);
}
string ReturnOne(out string other)
{
other = second;
return first;
}
:私はこれを行うには、2つの異なる方法を検討してきました。
私の質問:
- は、この例では2つの文字列を返すために良い方法はありますか?
- KeyValuePairを返す際に何か問題はありますか?
私が返すものはKeyValuePairではないので、私はその構造体の使用に躊躇しています。事はタプルです。あなたのアイデアをありがとう。 – Guy