这里的总菜鸟很温柔.我到处寻找,似乎无法找到答案.我如何压缩以下内容?
if (expression)
{
return true;
}
else
{
return false;
}
Run Code Online (Sandbox Code Playgroud)
我不能让它工作,因为它返回的东西与设置的东西.我已经看过这样的事了:
somevar = (expression) ? value1 : value2;
Run Code Online (Sandbox Code Playgroud)
就像我说的,请温柔:)
我想做一行if语句有多于1个动作.
默认是这样的:
(if) ? then : else
userType = (user.Type == 0) ? "Admin" : "User";
Run Code Online (Sandbox Code Playgroud)
但我不需要"别的",我需要一个"别的如果"
像多行中那样:
if (user.Type == 0)
userType = "Admin"
else if (user.Type == 1)
userType = "User"
else if (user.Type == 2)
userType = "Employee"
Run Code Online (Sandbox Code Playgroud)
单线有可能吗?