Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
If statement
Message
 
 
To
28/02/2008 09:39:38
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01297350
Message ID:
01297366
Views:
16
>Using VS05 and C#. The following two examples produce different results. My goal is to fill myvar with either myvar1 or myvar2. Sometimes my myvar1 is empty, in which case I want the value in myvar2.
>
>When I step through my code in example 1 and myvar1 is empty, the code performs this 'myvar = myvar2' which is what I expect. However, the next line of code then performs this 'myvar = myvar1' which I don't expect. Why does this happen?
>
>The only way I can get the results I want is to change example 1 to look like example 2. Example 2 works all the time. Why doesn't example 1 work like example 2?
>
>
>//Example 1
>if (myvar1 == "") myvar = myvar2; myvar = myvar1;
>
>//Example 2
>if (myvar1 == "")
>  {
>    myvar = myvar2;
>  }
>  else
>  {
>    myvar = myvar1;
>  }
>
>
>Thanks,
>
>Jerry

Never seen this written this way. I would say the second example increases the readabily of the code even if it's more verbose.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform