Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is Empty or Null
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP
Database:
MS SQL Server
Divers
Thread ID:
01303548
Message ID:
01303577
Vues:
12
>>Hi everybody,
>>
>>Ok, another beginner question today.
>>
>>I'm looking at the following code:
>>
>> if ((this.lsbUsers.SelectedItem != null || this.lsbUsers.Text != string.Empty)
>>            && this.LsbRoles.SelectedValue != null)
>>
>>and although I'm not selecting anything in lsbRoles it's going inside this block of code producing the error.
>>
>>I see that the SelectedValue is an empty string in the watch window. So, my first guess was that I need to be able to test for both conditions (empty and null).
>>
>>Googling led me to string.IsEmptyAndNull method, but then I hit this
>>http://msmvps.com/blogs/bill/archive/2006/04/04/89234.aspx
>>
>>So, do you think it's OK to use this method in code or rather use two comparisions instead?
>>
>
>I'd personally use string.IsNullOrEmpty() when I need to check for both conditions. The case you linked to definitely looked like a compiler optimization issue - I've not run into any problems in any of my code.

Thanks, Paul, going to experiment with yours and Greg suggestions.
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