I’m not sure if this is a feature that c# supports, but it is a construct that I use in javascript programming and I am hoping to use the construct with c# if it supports it (.net Framework 3.5).
I have the following working code:
if (user.Status == AccountStatus.Active) {
status = true;
} else {
status = false;
}
I would like to shorten it as follows:
status = (user.Status == AccountStatus.Active);
In Javascript this will assign the true / false result of the evaluation within the parenthesis. This appears not to work for me in c#, and results in a generic compilation error.
Is there an alternative way to achieve this in a way that is compact?
That should work fine.
As should:
Your syntax is correct.