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

Click here to load this message in the networking platform