Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.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.net 将Directory.GetFiles转换为Systems.Collections.Generic.List(字符串)_Vb.net - Fatal编程技术网

Vb.net 将Directory.GetFiles转换为Systems.Collections.Generic.List(字符串)

Vb.net 将Directory.GetFiles转换为Systems.Collections.Generic.List(字符串),vb.net,Vb.net,我发现了一个函数,它使用System.Collections.Generic.List(字符串)填充一个数组,然后与For-Each语句一起使用 这将用目录.GetFiles(strFolderPath)填充 我似乎无法让转换正常工作。有人能给我指出正确的方向吗 我做到了: Dim strAttachments As New StringCollection() strAttachments.AddRange(Directory.GetFiles(GlobalVariables.strFolde

我发现了一个函数,它使用
System.Collections.Generic.List(字符串)
填充一个数组,然后与For-Each语句一起使用

这将用
目录.GetFiles(strFolderPath)
填充

我似乎无法让转换正常工作。有人能给我指出正确的方向吗

我做到了:

Dim strAttachments As New StringCollection()
strAttachments.AddRange(Directory.GetFiles(GlobalVariables.strFolderPath))
但我明白了

错误1类型的值 无法转换“System.Collections.Specialized.StringCollection” 到“System.Collections.Generic.List”(共个) 字符串“”。C:\Users\JamesL.FRESHINSURANCE\documents\visual studio 2012\Projects\Fresh eDoc System\Fresh eDoc System\MainForm.vb 616 145新鲜eDoc系统


我想您应该使用
列表(T)
,而不是
StringCollection

Dim files As String() = Directory.GetFiles(GlobalVariables.strFolderPath)
Dim strAttachments As New List(Of String)(files)

嗨,蒂姆。我自己用同一行代码解决了这个问题:D谢谢老兄。这个问题的第一部分有点让人困惑,你的解决方案不使用泛型列表来填充数组,而是使用数组来填充泛型列表。您是否同时引用了不同的方法(单独考虑)?