×

VB.Net Programs

VB.Net program to overload non-member functions

By Nidhi Last Updated : November 15, 2024

Overloading non-member functions in VB.Net

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

Program/Source Code:

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

VB.Net code to overload non-member functions

'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
Press any key to continue . . .

Explanation:

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

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

VB.Net Basic Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.