【发布时间】:2022-08-22 23:38:31
【问题描述】:
我试图找到与 VB 的 \"System.Data.DataRow.Item\" 等效的东西,但我找不到。我正在将 VB 代码重写为 C#,而且我是 C# 的新手。菜鸟问题,可能。我想你们会有一些很好的见解。代码 sn-p 如下。我发现另一个堆栈溢出帖子有类似的问题,但答案对我没有帮助,所以我发布了这个。
这也是错误:Error CS1061 \'DataRow\' does not contain a definition for \'Item\' and no accessible extension method \'Item\' accepting a first argument of type \'DataRow\' could be found (are you missing a using directive or an assembly reference?)
...
// C# code
if (Reader.HasRows) // check that data exists
{
var winshare = new DataTable();
winshare.Load(Reader);
foreach (DataRow row in winshare.Rows)
{
string path = row.Item[\"List_Item\"];
path = path + @\"\\Out\";
GlobalVariables.pwc = row.Item[\"Sublist_Id\"];
...
...
// VB code
If Reader.HasRows Then // check that data exists
Dim winshare As DataTable = New DataTable
winshare.Load(Reader)
For Each row As DataRow In winshare.Rows
Dim path As String = CStr(row.Item(\"List_Item\"))
path = path + \"\\Out\"
pwc = CStr(row.Item(\"Sublist_Id\")) // Used to determine archive path also
...
-
请尝试:
row.Item[\"Sublist_Id\"];这是一个 C# 数组。 docs.microsoft.com/en-us/dotnet/api/… -
@MarkusMeyer 它不是一个数组,它是一个索引器。但是,与 VB 一样,它使用与数组相同的访问权限。
-
这回答了你的问题了吗? VB.Net to C# conversion errors
-
抱歉,我实际上确实从括号中进行了更改(我将在原始帖子上进行编辑以避免更多混淆)但不幸的是,在使用索引器括号 [] @Craig 时我仍然遇到完全相同的错误
-
@MarkusMeyer我很抱歉,我实际上已经更改了索引括号。 (我在原始帖子中进行了更改以避免混淆)但是即使使用正确的索引括号,我仍然会遇到相同的错误。