因此,我不确定这样的事情是否有可能。也许?只是好奇...使用方法的返回同时分配给多个变量
// Initial values of the strings.
string variable1 = "Something", variable2 = "SomethingElse";
// New values for the strings. ** LEFT OF ASSIGNMENT OPERATOR WON'T COMPILE **
(variable1, variable2) = DoSomething(variable1, variable2);
// Method to modify the initial strings.
public List<string> DoSomething(string v1, string v2)
{ ...; return new List<string> { v1, v2 }; }
[这个功能](HTTPS: //docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7#tuples)对于C#7来说是新的 - 它不会在任何比这更早的版本中工作。 –
就我个人而言,我只知道LISP编程语言('multiple-value-setq'形式)的功能。主流语言只能从函数返回一个对象,并在语句中分配一个变量。哦,我多么想念LISP功能...... –