Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将VB转换为C#(数组)_C#_Arrays_Vb.net - Fatal编程技术网

将VB转换为C#(数组)

将VB转换为C#(数组),c#,arrays,vb.net,C#,Arrays,Vb.net,目前我对VB.net不太熟悉,在将以下代码转换为C#时遇到一些问题 到目前为止,我已经: ArrayList itemList = new ArrayList(); string[] strMyitemList = new string[itemList.Count -1]; for (int x = 0; x <= (itemList.Count - 1); x++) { strMyitemList[x]

目前我对VB.net不太熟悉,在将以下代码转换为C#时遇到一些问题

到目前为止,我已经:

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

            for (int x = 0; x <= (itemList.Count - 1); x++)
            {
                strMyitemList[x] = itemList(x);
            }
arraylistitemlist=newarraylist();
string[]strMyitemList=新字符串[itemList.Count-1];

for(int x=0;x
itemList
是一个
ArrayList
,它有一个索引器。在C中,您可以将它们与
[]
一起使用:

strMyitemList[x] = (string)itemList[x];
但是现在没有理由使用
ArrayList
。请使用强类型的
列表


itemList
是一个具有索引器的
ArrayList

strMyitemList[x] = (string)itemList[x];
但是现在没有理由使用
ArrayList
。请使用强类型的
列表


不要再使用
ArrayList
,如果你不熟悉vb.net,没有任何理由阻止你编写工作的C#代码?@user202729我需要将已经存在的东西从vb.net转换成C#。但是,我试图理解vb来转换它。更改strMyitemList[x]=itemList(x);到strMyitemList[x]=项目列表[x];在C#中,声明数组时不应使用
itemList.Count-1
。它只在VB.NET中使用,因为它处理数组的方式不同。不要再使用
ArrayList
,没有理由如果你不熟悉VB.NET,是什么阻止你编写工作的C#代码?@user202729我需要转换一些已经存在的东西从VB.net存在到C#。但是,正在尝试理解VB以将其转换。将strMyitemList[x]=itemList(x);更改为strMyitemList[x]=itemList[x];在C#中,在声明数组时不应使用
itemList.Count-1
。它仅在VB.NET中使用,因为它处理数组的方式不同。谢谢Tim,我注意到我将方括号添加到strMyitemList中,但没有添加itemList(也忘记了cast)。谢谢Tim,我注意到我将方括号添加到strMyitemList中,但没有添加到itemList中(也忘了演员)。
strMyitemList[x] = itemList[x];