Home >>VB.Net Built-in Functions >VB.Net Program to overload non-member functions

VB.Net Program to overload non-member functions

Write a VB.Net Program to overload non-member functions

Here, to calculate the sum of arguments based on the various types of arguments, we can overload the non-member Add() function.

Program :

The source code for non-member feature overload is given below. The program given is compiled and successfully executed.

'VB.net program to overload non-member function.


Module Module1
    Public Sub Add(ByVal num1 As Double, ByVal num2 As Integer)
        Dim sum As Double = 0
        sum = num1 + num2
        Console.WriteLine("Sum is: {0}", sum)
    End Sub
    Public Sub Add(ByVal num1 As Integer, ByVal num2 As Double)
        Dim sum As Double = 0
        sum = num1 + num2
        Console.WriteLine("Sum is: {0}", sum)
    End Sub
    Sub Main()
        Add(12.6, 20)
        Add(10, 23.7)
    End Sub
End Module
	
Output:
Sum is: 32.6
Sum is: 33.7
Explanation:

We created a Module1 module in the program above. Here, we built two Add() methods based on the various types of arguments to overload non-member functions.

The Main() method is the program's entry point, here we called both the Add() function that will print the sum of the arguments you specified on the console screen.


No Sidebar ads