VB.net Program to Demonstrate the Nullreferenceexception

You are currently viewing VB.net Program to Demonstrate the Nullreferenceexception

VB.Net program to demonstrate the NullReferenceException

'Vb.Net program to demonstrate the NullReferenceException.

Module Module1
    Class Sample
        Public Sub SayHello()
            Console.WriteLine("Hello World")
        End Sub
    End Class

    Sub Main()
        Try
            Dim S As New Sample()

            S = Nothing
            S.SayHello()
        Catch e As NullReferenceException
            Console.WriteLine(e.Message)
        End Try
    End Sub
End Module
Object reference not set to an instance of an object.
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply