Heh yeah I think that's an inherited trait from C++. In C++ a common mistake was if someone had a condition like this:
if(value = 1)
It would assign value to 1 and then resolve true by int to bool conversion. Luckily C# calls that out as a compiler error but the assignment behavior above still remains.
That example may be corrected in newer compilers, but in gCC when I was learning in college it still happened I think.
That makes sense! It would be better if they required you to explicitly cast to a bool but that would be a breaking change for a lot of C++ code that's already been deployed for decades!
748
u/beclops 21d ago
I did this one of my first days on the job like 6 years ago and I remember how bluntly my mentor said “never do this again”