我有一个需要返回两个字符串的函数.我考虑过两种不同的方法:
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;
}
Run Code Online (Sandbox Code Playgroud)
我想使用KeyValuePair <>方法,但我觉得我误用了创建这个对象的目的.
我的问题:
这将是我的首选方法.KeyValuePair非常冗长.
String[] ReturnPair()
{
return new [] { first, second };
}
Run Code Online (Sandbox Code Playgroud)