VB.Net program to overload Main() function

Here, we are going to learn how to overload Main() function in VB.Net?
Submitted by Nidhi, on December 25, 2020 [Last updated : March 06, 2023]

How to overload Main() function in VB.Net?

Here, we will overload the Main() function based on different number arguments, but the Main() function with string array argument is the entry point for the program.

Program/Source Code:

The source code to overload the Main() function is given below. The given program is compiled and executed successfully.

VB.Net code to overload Main() function

'VB.net program to overload Main() function.

Module Module1
    Sub Main(ByVal val As Integer)
        Console.WriteLine("Val : {0}", val)
    End Sub
    
    Sub Main(ByVal val As Double)
        Console.WriteLine("Val : {0}", val)
    End Sub

    Sub Main(ByVal args As String())
        Main(10)
        Main(22.67)
    End Sub
End Module

Output:

Val : 10
Val : 22.67
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1. Here, we created three Main() functions.

The Main() function with the string array argument is the entry point for the program. Here, we called both overloaded methods that will print the argument passed into the function on the console screen.

VB.Net Basic Programs »





Comments and Discussions!

Load comments ↻





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