【问题标题】:Unable to cast object of type 'WhereArrayIterator`1[System.String]' to type 'System.String[]'无法将“WhereArrayIterator`1[System.String]”类型的对象转换为“System.String[]”类型
【发布时间】:2017-11-24 18:08:22
【问题描述】:

我试图从一个目录中获取子目录路径,但是忽略了一些文件夹,下面的代码给了我这个错误,

System.InvalidCastException:无法将“WhereArrayIterator`1[System.String]”类型的对象转换为“System.String[]”类型

谁能帮忙?

Dim subdirectoryEntries() As String = Directory.GetDirectories(ConfigurationSettings.AppSettings("FsRoot") & Path.DirectorySeparatorChar & readerClientList.GetString(0)).
Where(Function(name) Not name.EndsWith(folder, StringComparison.OrdinalIgnoreCase))

【问题讨论】:

  • 您如何处理 subDirectoryEntries?根据答案,您可能最好将其类型更改为IEnumerable(Of String),而不是转换GetDirectories 的结果。

标签: .net arrays vb.net directory


【解决方案1】:

getdirectories 的结果是 iqueryable 的结果,你必须添加一个 .例如 tolist 或 toarray 或类似的方法来转换为这个方法。

希望有帮助

【讨论】:

  • 美丽。我试图使用 list.TypeOf ,遇到了这个问题。我发布了一个新问题,偶然发现了这个问题。
猜你喜欢
  • 2014-03-14
  • 2012-09-07
  • 2021-04-26
  • 2017-03-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多