c# - Error : possible unintended reference comparison to get a value comparison cast the right hand -


i have following code gives warning "possible unintended reference comparison; value comparison, cast right hand side type string":

// ocontrol of type control if ((ocontrol.name == odatarowview["conname"].tostring())) {    //do stuff    } else {    //do other stuff } 

i've tried fix using each of following still warning

if ((ocontrol.name == convert.tostring(odatarowview["conname"]))) {    //do stuff    } else {    //do other stuff }   if ((ocontrol.name == (string)odatarowview["conname"])) {    //do stuff    } else     {    //do other stuff } 

please explain reason still warning , best practice way deal this?

these options work:

if (equals(ocontrol.name, odatarowview["conname"])) // best option  if ((string)ocontrol.name == odatarowview["conname"].tostring()) // assuming neither item null  if (ocontrol.name string == odatarowview["conname"] string) // assuming second item string 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -