如何在VB.Net中过滤字符串数组?

什么是VB.Net代码来过滤字符串数组?

我使用以下代码

Imports System.Reflection
Dim ass As Assembly = Assembly.GetExecutingAssembly()
Dim resourceName() As String = ass.GetManifestResourceNames()

返回一个String数组

如何过滤resourceName()变量?

我尝试了以下代码行

    Dim sNameList() As String 
        = resourceName.FindAll(Function(x As String) x.EndsWith("JavaScript.js"))

但是编译器返回以下错误

BC36625: Lambda expression cannot be converted to 'T()' because 'T()' is not a delegate type

我该如何纠正该错误? 还有其他解决方案可以解决我的问题吗?

评论
  • nerror
    nerror 回复
    Dim sNameList = resourceName.Where(Function(s) s.EndsWith("JavaScript.js"))
    

    In that case, sNameList is an IEnumerable(Of String), which is all you need if you intend to use a For Each loop over it. If you genuinely need an array:

    Dim sNameList = resourceName.Where(Function(s) s.EndsWith("JavaScript.js")).ToArray()
    

    The reason that your existing code didn't work is that Array.FindAll is Shared and so you call it on the Array class, not an array instance:

    Dim sNameList = Array.FindAll(resourceName, Function(s) s.EndsWith("JavaScript.js"))