visual studio – Variable assignment inside an If statement – Can that be turned into a VS Warning?


Like (presumably) many programmers out there, during many years of programming, I have never put a variable assignment inside an IF statement. On the other hand, I will admit that at times I have accidentally typed “=” inside an IF clause where I should have put “==”.

I am predominantly referring here to those times when there is more than one clause in an IF statement; for example…

if (accidentalAssignment = "Hello" && desiredIfClauseType == "World")

I assume no Intelisense ‘warning’ has been assigned to this sort of thing; perhaps because it’s not ‘illegal’. (If I am wrong about that, please tell me). Assuming I am correct, is there a way to create such a warning? For those of us who have lost time debugging this sort of scenario, it could serve as the basis for a helpful warning.

Leave a Reply

Your email address will not be published. Required fields are marked *