Home »
VB.Net »
VB.Net Programs
VB.Net program to pass an object to the non-member function
By Nidhi Last Updated : November 16, 2024
Pass an object to the non-member function in VB.Net
Here, we will create a class and a non-member function, then pass an object to the non-member function.
Program/Source Code:
The source code to pass an object to the non-member function is given below. The given program is compiled and executed successfully.
VB.Net code to pass an object to the non-member function
'VB.Net program to pass an object to the
'non-member function.
Class Sample
Sub SayHello()
Console.WriteLine("Hello World")
End Sub
End Class
Module Module1
Sub NonMemberFun(ByVal obj As Sample)
obj.SayHello()
End Sub
Sub Main()
Dim S As New Sample()
NonMemberFun(S)
End Sub
End Module
Output
Hello World
Press any key to continue . . .
Explanation
In the above program, we created a module Module1 that contains the Main() function. We created a Sample class that contains a SayHello() method. We also created a NonMemberFun() that accepts the object of the sample class as an argument. In the NonMemberFun() function, we called SayHello() method that will print a "Hello World" message on the console screen.