从vb.net转换为c#时出错 [英] Error while converting from vb.net to c#

查看:86
本文介绍了从vb.net转换为c#时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





当我尝试将以下代码行从vb.net转换为c#时显示错误。



VB.NET代码:lt.Text = IIf(CType(dg.Controls(i),CheckBox).Checked,True,False)



转换后的c#代码:

lt.Text ==(((CheckBox)dg.Controls(i))。选中?true:false)



请帮我解决这个问题。

Hi,

when I am trying to convert the below line of code from vb.net to c# showing an error.

VB.NET Code: lt.Text = IIf(CType(dg.Controls(i), CheckBox).Checked, True, False)

Converted c# code:
lt.Text == (((CheckBox)dg.Controls(i)).Checked ? true : false)

Please help me for resolving this.

推荐答案

假设你要分配,而不是比较。还假设您要执行数组索引操作:



Assuming that you want to assign, not compare. Also assuming that you mean to perform an array index operation:

lt.Text = ((CheckBox)dg.Controls[i]).Checked





或者,如果变量dg是静态类型的:





Or, if the variable dg is statically typed:

lt.Text = dg.Controls[i].Checked


试试这样:



Try it like this :

lt.Text = Convert.ToString(((CheckBox)dg.Controls(i)).Checked ? true : false);


这篇关于从vb.net转换为c#时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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