Is it possible to make a comparison (if equal to 1 or equal to null
) simpler than the one made in my code?
@((Model.Visibilidade == 1 || Model.Visibilidade == null) ? "checked" : "")
Is it possible to make a comparison (if equal to 1 or equal to null
) simpler than the one made in my code?
@((Model.Visibilidade == 1 || Model.Visibilidade == null) ? "checked" : "")
It does not work.
I would do so:
@((Model.Visibilidade == null || Model.Visibilidade == 1) ? "checked" : "")
In this case it does not give a problem because it is a int?
, but in cases of types by reference it would give error. If it is null and try to make the comparison with a value will give error, then it is correct is to buy the null first. To maintain consistency I would always do this order, even if in this case I can compare the value first.