Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
If statement
Message
 
 
À
28/02/2008 09:39:38
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01297350
Message ID:
01297366
Vues:
17
>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform