Home >>VB.Net Built-in Functions >VB.Net Program to overload Main() function

VB.Net Program to overload Main() function

Write a VB.Net Program to overload Main() function

Here, based on various number arguments, we can overload the Main() function, but the Main() function with string array argument is the program's entry point.

Program :

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

'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
Explanation:

We created a Module1 module in the program above. Here, three main roles have been developed.

An entry point for the program is the Main() function with the string array argument. Here, we have called all overloaded methods that print the argument passed to the console screen function.


No Sidebar ads