Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Possible unintended reference comparison
Message
De
05/03/2010 14:46:56
 
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Divers
Thread ID:
01452752
Message ID:
01452852
Vues:
35
>>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?
>Frank,
>One more bit of advice since you seem to be getting started. Even with casting the left side of the equation appropriately, you will get an error if dt is null. You may already have that covered but I thought I'd throw it in the hat. That still catches me fairly often, even after several years of working with .NET. Old habits die hard.

Thanks.
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