Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Possible unintended reference comparison
Message
De
05/03/2010 08:36:41
 
 
À
05/03/2010 08:28:15
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01452752
Message ID:
01452764
Vues:
29
>>Hi,
>>
>>I have this line of code:
>>
>>
if (dt.Rows[0]["ClientType"] == "Individual")
>>
>>which gives me this warning:
>>
>>
Possible unintended reference comparison; to get a value comparison, cast the left hand side to type 'string'
>>
>>I have tried things like this:
>>
>>
if ((String)(dt.Rows[0]["ClientType"]) == "Individual")
>>
>>and:
>>
>>
if ((dt.Rows[0]["ClientType"]).ToString() == "Individual")
>>
>>neither of which help.
>>
>>The code runs fine, but I would like to understand the warning and what do I need to do here?
>
>I am surprised the original worked. Both of the others you tried should be ok and the second would be preferred. The item you are getteing from a row is an object and needs to be cast to a string or use the built in method to get a string. Then you are comparing a string to a string. Did you try to make the change and then rebuild to verify the warning goes away?
>Tim

Thanks, once I rebuilt the solution the warning went away.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform