Home >>VB.Net Built-in Functions >VB.Net program to demonstrate the shared methods
Here, we are going to build a sample class of shared methods. Shared methods are class methods. There is no need to create an entity for shared methods to be called.
Program :The source code to display the shared methods is given below. The program given is compiled and successfully executed.
'VB.net program to demonstrate the Shared methods.
Module Module1
Class Sample
Shared Sub Fun1()
Console.WriteLine("Sample.Fun1() called")
End Sub
Shared Sub Fun2()
Console.WriteLine("Sample.Fun2() called")
End Sub
End Class
Sub Main()
Sample.Fun1()
Sample.Fun2()
End Sub
End Module
We created a Module1 module in the program above that contains a Sample Class. In the Sample class, we created two shared fun1() and fun2 methods (). We are not required to generate an entity to call the shared methods.
Finally, we created a Main() function, which is the program entry point, where we called all shared methods to print the right message on the console screen.