How to use method overloading in VB.NET

1 Answer

0 votes
Imports System
				
Public Module Module1
	Class Sample
        Public Sub Add(ByVal num1 As Integer, ByVal num2 As Integer)
            Dim sum As Integer = 0

            sum = num1 + num2
            Console.WriteLine("Sum = {0}", sum)
        End Sub

        Public Sub Add(ByVal num1 As Integer, ByVal num2 As Integer, ByVal num3 As Integer)
            Dim sum As Integer = 0

            sum = num1 + num2 + num3
            Console.WriteLine("Sum = {0}", sum)
        End Sub
    End Class
	Public Sub Main()
        Dim obj As New Sample()

        obj.Add(4, 8)
        obj.Add(9, 2, 5)
	End Sub
End Module



' run:
'
' Sum = 12
' Sum = 16
' 

 



answered Dec 18, 2023 by avibootz
...