This probably remains from learning C / C ++, where it was typical to bite this error:
if (variablename = true) { ... }
Before the compilers were set up to warn about this (note that it does the job, not the comparison), the above code silently executed an error.
However, if you had learned to write the expression differently, you would not have bitten the above code, because it would not compile in this form:
if (true = variablename) { ... }
In C #, however, this is not a problem, you can write it as you showed without comparison (if it is still compared with true ), or put a literal on the right side of the comparison operator.
source share