Does a printout of strResult actually show 'Doh.', or is it just the
debugger looking like it is stepping into the else part of the if
statement - sometimes the debugger can be misleading!

-----Original Message-----
From: Wareham, Matt [mailto:[EMAIL PROTECTED]] 
Sent: Friday, 17 May 2002 9:22 a.m.
To: [EMAIL PROTECTED]
Subject: [DOTNET] C# Nesting an If/Else inside of an If/Else???


Greetings,

I'm having some massive confusion over how to properly nest If/Else
statements in C#.... meaning can it even be done??  Below is a test
method I wrote to re-create what I'm thinking is an error.  If you run
the code below, it will run through both assignments of strResult in the
second If/Else group.

I can get this to work correctly if I remove the first Else statement at
the bottom of the code (the one that says strResult = "Doh.";).  But of
course doing this defeats the purpose of what I'm trying to do.

Has anyone else run into this problem?  What am I doing wrong???

Thanks,

-Matt



private void TestIfElse()
{
  string strT = "TEST";
  string strX = "Test Again";
  string strResult;
  if (strT.Length > 0)
  {
    if (strX.Length > 3)
    {
      strResult = "Yabba Dabba Doo.";
    }
    else
    {
      strResult = "Yadda Yadda Yadda.";
    }
  }
  else
  {
    strResult = "Doh.";
  }
}

This e-mail message, including any attachments, is for the sole use of
the intended recipient(s) and may contain confidential or privileged
information.  Any unauthorized review; use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact
the sender by reply e-mail and destroy the message.

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to