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谢谢老兄。这个问题的第一部分有点让人困惑,你的解决方案不使用泛型列表来填充数组,而是使用数组来填充泛型列表。您是否同时引用了不同的方法(单独考虑)?