I've just found a bug in my program (after some amount of debugging and tearing my hair)
bool first = true;
foreach (RdAbstractNode node in listNodes)
{
if (!first)
{
// do stuff (does not change first)
}
// do more stuff (does not change first)
}
As you can see first
is always true
- never changed. So if(!first)
is basically if(false)
.
The compiler did not generate a warning although it is set to level 4 (highest level).
How can I find similar if(false)
errors?
I'm using VS 2010, .Net 4.0 compiler, project setting .Net 2.0
With Resharper you'll get warnings like this
I don't know of a compiler feature that will help you - you need unit tests.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With