1

What is VB.Net code to filter a String Array ?

I use following code

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

that return a String array

How can I filter resourceName() variable ?

I tried following lines of code

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

but compiler return following error

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

How can I correct this error ? Is there another solution to solve my problem ?

1 Answer 1

3
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"))
Sign up to request clarification or add additional context in comments.

1 Comment

I'm confusing by Intellinsense that proposed FindAll() method when I enter a point just after resourceName ! But thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.