本文介绍了方法参数中的变量赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚发现了(通过发现一个bug),你可以这样做:
I've just found out (by discovering a bug) that you can do this:
string s = "3";
int i;
int.TryParse(s = "hello", out i); //returns false
是否有合法的使用使用赋值的返回值?
Is there a legitimate use of using the returned value of an assignment?
(显然我++
是,但是这是一样的吗?)
推荐答案
这是分配的,就像任何其他的表达式。这是有效的语法
An assignment is an expression just like any other. This is valid syntax.
出于同样的原因,这是有效的:
For the same reason this is valid:
int i;
int j;
int k;
i = j = k = 42;
这篇关于方法参数中的变量赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!