Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 16th, 2005, 04:58 AM
Registered User
 
Join Date: Aug 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
 
Old March 16th, 2005, 09:20 AM
Authorized User
 
Join Date: Mar 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi
   could you tell me the declaration of bool variable 'blnCommentThisLine'...
  bye

 
Old March 16th, 2005, 09:26 AM
Registered User
 
Join Date: Aug 2003
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

For completeness, the code snippet with variable declarations, is as follows:

bool isEnabled=true;
bool commentFlag=false;
bool blnCommentThisLine=false;
string strLine;
string strLineWithLogging;

if (isEnabled)
{
    commentFlag=true;
    strLine="xyz";
}
else
{
    strLineWithLogging = strLine;
    blnCommentThisLine = true; //**This line executes when isEnabled is true!
}







Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL LIKE Multiple Conditions takwirira ASP.NET 2.0 Basics 1 April 16th, 2008 06:24 AM
Query Executed multiple time. rupen Classic ASP Databases 4 January 11th, 2008 07:30 AM
IIf Function - Multiple conditions carrie09 Access 2 June 13th, 2007 10:27 AM
Multiple conditions austinf XSLT 1 May 5th, 2006 02:55 AM
Multiple conditions austinf XSLT 1 May 5th, 2006 02:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.