【发布时间】:2009-10-08 20:45:32
【问题描述】:
我有一个需要返回两个字符串的函数。我考虑了两种不同的方法来做到这一点:
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;
}
我想使用 KeyValuePair 方法,但我觉得我误用了创建此对象的目的。
我的问题:
- 在本例中是否有更好的方法来返回 2 个字符串?
- 返回 KeyValuePair 有什么问题吗?
【问题讨论】:
标签: c#