I used code converter to go from VB to C# and I get errors in c#. specifically, error on Item
and on string.join(",", Flop.ToArray)
. Error says it doesn't contain a definition for item
but it works in 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);
Try this:
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());
They three keys that were missing here
尝试...
Flop.Add(Dataset9.Tables[0].Rows[x]["Id"].ToString());
ToArray is a method()
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());
In a more concise way you can try below instead:
strAllRoleNames = string.Join(",", Dataset9.Tables[0].AsEnumerable()
.Select(C => Convert.ToString(C["Id"]))
.ToArray());
Try the below changes:
Dataset9.Tables[0].Rows[x].Item["Id"] => Dataset9.Tables[0].Rows[x]["Id"]
Flop.ToArray => Flop.ToArray()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.