Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is Empty or Null
Message
De
19/03/2008 19:00:40
 
 
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:
01303704
Vues:
15
>>>Ok, before I go absolutely crazy - why I can not make this simple thing to work?
>>>
>>>String selValue = this.lsbUsers.SelectedItem.ToString ;
>>>
>>>gives me
>>>
>>>Error 1 Cannot convert method group 'ToString' to non-delegate type 'string'. Did you intend to invoke the method? C:\Development\Visual Studio 2005\WebSites\FCAdmin\AddUsers\Default.aspx.cs 211 27 C:\...\FCAdmin\
>>
>>Did you mean:
>>
>>string selValue = this.lsbUsers.SelectedItem.ToString();
>>
>>
>>(note the parenthesis)
>>
>>or more probably:
>>
>>
>>string selValue = this.lsbUsers.SelectedItem.Text.ToString();
>>
>
>This is what I currently have - do you think it's a bad code? I would appreciate your corrections here:
>
>String selValue = this.lsbUsers.SelectedValue.ToString() ;
>
>        bool TestUser = (String.IsNullOrEmpty(selValue));
>        String selText = this.lsbUsers.Text.ToString();
>        bool TestUserText = String.IsNullOrEmpty(selText);
>        String SelRole = this.LsbRoles.SelectedValue.ToString();
>        bool TestRole = String.IsNullOrEmpty(SelRole) ;
>
>        //if ((!this.lsbUsers.SelectedItem != null && this.lsbUsers.Text != string.Empty)
>        //    && this.LsbRoles.SelectedValue != null)
>        if (TestUser == false && TestUserText == false && TestRole == false)
Aside from Paul's comments I see nothing wrong, If it's easily readable, it's all that matters

btw, do you know why IsNullOrEmpty() is a static method ?

My guess is, that it would error if the string would be null if it were a non-static method as in
string s = 'abc';

var xx = s.IsNullOrEmpty();

s = null
xx = s.IsNullOrEmpty(); // error I think
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform