将多个值返回给方法调用者 [英] Return multiple values to a method caller
本文介绍了将多个值返回给方法调用者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我阅读了这个问题的 C++ 版本,但实际上并没有明白了.
I read the C++ version of this question but didn't really understand it.
有人可以解释清楚是否可以用 C# 完成,以及如何完成?
Can someone please explain clearly if it can be done in C#, and how?
推荐答案
在 C# 7 及更高版本中,请参阅此答案.
In C# 7 and above, see this answer.
在以前的版本中,您可以使用 .NET 4.0+ 的元组:
In previous versions, you can use .NET 4.0+'s Tuple:
例如:
public Tuple<int, int> GetMultipleValue()
{
return Tuple.Create(1,2);
}
具有两个值的元组具有 Item1
和 Item2
作为属性.
Tuples with two values have Item1
and Item2
as properties.
这篇关于将多个值返回给方法调用者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文