Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,861 questions

51,782 answers

573 users

How to use the Func delegate in VB.NET

3 Answers

0 votes
Imports System

Public Class Program
	Public Shared Function AMessage() As String
        Return "May the Force be with you"
    End Function

    Public Shared Sub Main()
        Dim say As Func(Of String) = AddressOf AMessage
		
        Console.WriteLine(say())
    End Sub
End Class





' run:
'
' May the Force be with you
'

 



answered Jul 2, 2023 by avibootz
0 votes
Imports System

Public Class Program
	Public Shared Function Sum(ByVal x As Integer, ByVal y As Integer) As Integer
        Return x + y
    End Function

    Public Shared Sub Main()
        Dim add As Func(Of Integer, Integer, Integer) = AddressOf Sum
        
		Dim result As Integer = add(5, 5)
		
        Console.WriteLine(result)
    End Sub
End Class






' run:
'
' 10
'

 



answered Jul 2, 2023 by avibootz
0 votes
Imports System

Public Class Program
	Public Shared Function Sum(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer) As Integer
        Return x + y + z
    End Function

    Public Shared Sub Main()
        Dim add As Func(Of Integer, Integer, Integer, Integer) = AddressOf Sum
		
        Dim result As Integer = add(5, 5, 5)
		
        Console.WriteLine(result)
    End Sub
End Class






' run:
'
' 15
'

 



answered Jul 2, 2023 by avibootz

Related questions

1 answer 132 views
1 answer 117 views
1 answer 124 views
1 answer 94 views
94 views asked Jul 1, 2023 by avibootz
1 answer 91 views
1 answer 105 views
3 answers 126 views
126 views asked Jul 1, 2023 by avibootz
...