I’d like to do a single line if statement with more than 1 action.
Default is this:
(if) ? then : else
userType = (user.Type == 0) ? "Admin" : "User";
But I don’t need an “else” only, I need an “else if”
like that in multi line:
if (user.Type == 0)
userType = "Admin"
else if (user.Type == 1)
userType = "User"
else if (user.Type == 2)
userType = "Employee"
Is there a possibility for that in single line?
Sounds like you really want a
Dictionary<int, string>or possibly aswitchstatement…You can do it with the conditional operator though:
While you could put that in one line, I’d strongly urge you not to.
I would normally only do this for different conditions though – not just several different possible values, which is better handled in a map.