How to use the Func delegate with Linq in VB.NET

1 Answer

0 votes
Imports System
Imports System.Linq
Imports System.Collections.Generic

Public Class Program
	Public Shared Sub Main()
        Dim Has4Letters As Func(Of String, Boolean) = Function(str) str.Length = 4
			
        Dim words As String() = {
				"play", "sing", "sci", "fi", "game", "pro", 
				"dev", "five", "moon", "c#", "net", "cool", "programming"
		}
			
        Dim FourLetterWords As IEnumerable(Of String) = words.Where(Has4Letters)

        For Each word In FourLetterWords
            Console.WriteLine(word)
        Next
    End Sub
End Class





' run:
'
' play
' sing
' game
' five
' moon
' cool
'

 



answered Jul 2, 2023 by avibootz

Related questions

1 answer 166 views
3 answers 190 views
190 views asked Jul 2, 2023 by avibootz
1 answer 154 views
1 answer 104 views
1 answer 124 views
1 answer 112 views
112 views asked Jul 1, 2023 by avibootz
3 answers 138 views
138 views asked Jul 1, 2023 by avibootz
...