Perl 有能力做:
my ($a,$b,$c,$d) = foo();
其中 foo
返回 4 个变量,而不是一次分配一个变量。 C# 中有类似的东西吗?
最佳答案
不,基本上。选项:
object[] values = foo();
int a = (int)values[0];
string b = (string)values[1];
// etc
或:
var result = foo();
// then access result.Something, result.SomethingElse etc
或:
int a;
string b;
float c; // using different types to show worst case
var d = foo(out a, out b, out c); // THIS WILL CONFUSE PEOPLE and is not a
// recommendation
关于c# - 如何在一个语句中分配给变量列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17924858/