将VB转换为C#(数组)

时间:2018-04-06 08:16:20

标签: c# arrays vb.net

我目前对VB.net不是很熟悉,并且在将以下代码转换为C#时遇到了一些麻烦。

Dim itemList As New ArrayList
Dim strMyitemList(itemList.Count - 1) As String

        For x = 0 To (itemList.Count - 1)
            strMyitemList(x) = itemList(x)
        Next

到目前为止,我已经:

ArrayList itemList = new ArrayList();
string[] strMyitemList = new string[itemList.Count -1];

            for (int x = 0; x <= (itemList.Count - 1); x++)
            {
                strMyitemList[x] = itemList(x);
            }

我在“itemList(x)”上收到错误CS0149“预期的方法名称”。

由于

1 个答案:

答案 0 :(得分:5)

itemList是一个ArrayList,它有一个索引器。在C#中,您可以使用[]

strMyitemList[x] = (string)itemList[x];

但是现在没有理由使用ArrayList。使用强类型List<string>

strMyitemList[x] = itemList[x];