Home »
VB.Net »
VB.Net Programs
VB.Net program to check an object is initialized or not
By Nidhi Last Updated : October 13, 2024
How to check an object is initialized or not in VB.Net?
Here, we will use IsNothing() function to check an object is initialized or not.
Program/Source Code:
The source code to check an object is initialized or not is given below. The given program is compiled and executed successfully.
VB.Net code to check whether an object is initialized or not
'Vb.Net program to check an object is initialized or not.
Module Module1
Class Sample
Public Sub SayHello()
Console.WriteLine()
End Sub
End Class
Sub Main()
Dim obj As Sample
Dim ret As Boolean
ret = IsNothing(obj)
If (ret = True) Then
Console.WriteLine("Object obj is not initialized")
Else
obj.SayHello()
End If
End Sub
End Module
Output:
Object obj is not initialized
Press any key to continue . . .
Explanation:
In the above program, we created a module Module1 that contains a class Sample and a Main() function. The Sample class contains a method SayHello(). The SayHello() method is used to print the "Hello World" message on the console screen.
The Main() function is the entry point for the program. And, we created a reference of Sample class but did not initialize the reference of Sample class. Then we checked reference is initialized or not using IsNothing() function.
VB.Net Basic Programs »