我使用代码转换器从VB转到C#,我在c#中遇到错误。具体而言,Item
和string.join(",", Flop.ToArray)
上的错误。错误说它不包含item
的定义,但它适用于VB。
VB
Dim Flop As New List(Of String)
For x As Integer = 0 To Dataset9.Tables(0).Rows.Count - 1 'ROWS
Flop.Add(Dataset9.Tables(0).Rows(x).Item("Id"))
Next
strAllRoleNames = String.Join(",", Flop.ToArray)
C#
List<string> Flop = new List<string>();
for (int x = 0; x <= Dataset9.Tables[0].Rows.Count - 1; x++)
{
Flop.Add(Dataset9.Tables[0].Rows[x].Item["Id"]);
}
strAllRoleNames = string.Join(",", Flop.ToArray);
答案 0 :(得分:7)
试试这个:
List<string> Flop = new List<string>();
for (int x = 0; x <= Dataset9.Tables[0].Rows.Count - 1; x++)
{
Flop.Add(Dataset9.Tables[0].Rows[x]["Id"].ToString());
}
strAllRoleNames = string.Join(",", Flop.ToArray());
这里缺少三把钥匙
答案 1 :(得分:2)
尝试...
Flop.Add(Dataset9.Tables[0].Rows[x]["Id"].ToString());
答案 2 :(得分:2)
ToArray是一个方法()
List<string> Flop = new List<string>();
for (int x = 0; x <= Dataset9.Tables[0].Rows.Count - 1; x++)
{
Flop.Add(Dataset9.Tables[0].Rows[x]["Id"]);
}
strAllRoleNames = string.Join(",", Flop.ToArray());
答案 3 :(得分:1)
以更简洁的方式,您可以尝试以下方式:
strAllRoleNames = string.Join(",", Dataset9.Tables[0].AsEnumerable()
.Select(C => Convert.ToString(C["Id"]))
.ToArray());
答案 4 :(得分:0)
尝试以下更改:
Dataset9.Tables[0].Rows[x].Item["Id"] => Dataset9.Tables[0].Rows[x]["Id"]
Flop.ToArray => Flop.ToArray()