ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to check an object is initialized or not

Here, we are going to learn how to check an object is initialized or not in VB.Net?
Submitted by Nidhi, on January 06, 2021

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 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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.