简体   繁体   English

C#:直接将测试结果分配给变量

[英]C#: Assign test result directly to variable

Is it possible to assign the result of a test directly to a variable? 是否可以将测试结果直接分配给变量?

I want to do something like 我想做类似的事情

c = ( a == b )

instead of 代替

if ( a == b )
{
 c = true;
}
 else
{
 c = false;
}

Is this possible? 这可能吗?

Yes, of course. 当然是。

Which you can very easily test with the compiler. 您可以很容易地使用编译器进行测试。

int a = 1, b = 2;
bool c = a == b;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM