Multiple If..Else conditions executed problem
I have a situation where multiple clauses of an if..else construct are executing. The code within the true block executes, followed by the second (and last) line of the false block.
A snippet of my C# code is as follows:
bool isEnabled=true;
if (isEnabled)
{
commentFlag=true;
strLine="xyz";
}
else
{
strLineWithLogging = strLine;
blnCommentThisLine = true; //**This line executes when isEnabled is true!
}
Hence, 'blnCommentThisLine = true' also executes when 'isEnabled' is true. I can avoid this, by using a switch construct, but this seems very odd.
Has anyone encountered this before or can offer any suggestions?
|