可能的无意义参考比较,要获得值比较,将左侧投射到'String' [英] Possible unintendent reference comparison, to get a value comparison, cast the left hand side to 'String'

查看:81
本文介绍了可能的无意义参考比较,要获得值比较,将左侧投射到'String'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友们,



我在c#.net应用程序中遇到以下错误请帮助我

编辑按钮事件:



  if (dgvUserDetails.SelectedRows [i] .Cells [ 0 ]。值==   Admin
{
rbAdmin.Checked = true ;
}
else if (dgvUserDetails.SelectedRows [i] .Cells [< span class =code-digit> 0 ]。值== 管理
{
rbManagement.Checked = true ;
}
else
{
rbUser.Checked = true ;
}









问候,

Vivek .R

解决方案

值是一个对象 - 所以它是对string类型对象的引用,但它与类型对象不同字符串。

你必须使用Convert.ToString或对象的ToString()将其强制转换为字符串...


按照建议,从
$更改b $ b

Quote:

if(dgvUserDetails.SelectedRows [i] .Cells [0] .Value ==Admin)



to

 if(dgvUserDetails.SelectedRows [i] .Cells [0] .Value.ToString()==Admin)


Dear Frnds,

I have got the following errors in c# .net application please help me
edit buttton event:

if (dgvUserDetails.SelectedRows[i].Cells[0].Value == "Admin")
                {
                    rbAdmin.Checked = true;
                }
                else if (dgvUserDetails.SelectedRows[i].Cells[0].Value == "Management")
                {
                    rbManagement.Checked = true;
                }
                else
                {
                    rbUser.Checked = true;
                }





With Regards,
Vivek .R

解决方案

Value is an object - so it's a reference to an object of type string but it's not the same as an object of type string.
You have to cast it to string using Convert.ToString or object's ToString()...


As suggested, change from

Quote:

if (dgvUserDetails.SelectedRows[i].Cells[0].Value == "Admin")


to

if (dgvUserDetails.SelectedRows[i].Cells[0].Value.ToString() == "Admin")


这篇关于可能的无意义参考比较,要获得值比较,将左侧投射到'String'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆