C#: Assign test result directly to variable

╄→尐↘猪︶ㄣ 提交于 2019-12-11 19:44:02

问题


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?


回答1:


Yes, of course.

Which you can very easily test with the compiler.

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


来源:https://stackoverflow.com/questions/18183591/c-assign-test-result-directly-to-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!