将vb转换为c#(foreach语句中需要Type和identifier)
本文关键字:Type identifier 语句 转换 vb foreach | 更新日期: 2023-09-27 17:59:43
vb代码:
Dim janTbl As Janus.Windows.GridEX.GridEXTable
For Each janTbl In lvtoolpartsinfo.Tables`
c#代码:
Janus.Windows.GridEX.GridEXTable janTbl = new Janus.Windows.GridEX.GridEXTable();
foreach (janTbl in lvtoolpartsinfo.Tables)
{ }
错误:foreach语句中需要类型和标识符
编辑:
c#代码:
foreach (Janus.Windows.GridEX.GridEXTable janTbl in lvtoolpartsinfo.Tables)
janTbl.Columns[0].Visible = false;
janTbl.Columns[1].Caption = "Part Number";
janTbl.Columns[1].ShowRowSelector = true;
janTbl.Columns[1].EditType = Janus.Windows.GridEX.EditType.NoEdit;
janTbl.Columns[1].Width = 120;
错误:
line 3:The name 'janTbl' does not exist in the current context
line 4 ...
line 5..
删除此行:
Janus.Windows.GridEX.GridEXTable janTbl = new Janus.Windows.GridEX.GridEXTable();
然后,您只需修复foreach
语句,使其包含janTbl
的类型,即可设置为:
foreach (Janus.Windows.GridEX.GridEXTable janTbl in lvtoolpartsinfo.Tables)
{
// ...
}
您缺少大括号:
foreach (var janTbl in lvtoolpartsinfo.Tables)
{ // <--- don't forget this
janTbl.Columns[0].Visible = false;
janTbl.Columns[1].Caption = "Part Number";
janTbl.Columns[1].ShowRowSelector = true;
janTbl.Columns[1].EditType = Janus.Windows.GridEX.EditType.NoEdit;
janTbl.Columns[1].Width = 120;
} // <--- and this
如果没有大括号,则只有foreach()
语句之后的第一行是循环的一部分。之后的代码在循环之外,它和你写的一样:
foreach (Janus.Windows.GridEX.GridEXTable janTbl in lvtoolpartsinfo.Tables)
janTbl.Columns[0].Visible = false;
janTbl.Columns[1].Caption = "Part Number";
janTbl.Columns[1].ShowRowSelector = true;
janTbl.Columns[1].EditType = Janus.Windows.GridEX.EditType.NoEdit;
janTbl.Columns[1].Width = 120;