Home >>VB.Net Built-in Functions >VB.Net program to demonstrate the "Me" object

VB.Net program to demonstrate the "Me" object

Write a VB.Net program to demonstrate the "Me" object

Here, the data member of the class uses the Me object within the class to access the data member. The 'Me' object in vb.net uses a point-current object.

Program :

Below is the source code for demonstrate the 'Me' object. The program given is compiled and successfully executed.

'VB.net program to demonstrate the "Me" object.


Module Module1
    Class Sample
        Dim num1 As Integer
        Dim num2 As Integer
        Sub New(ByVal num1 As Integer, ByVal num2 As Integer)
            Me.num1 = num1
            Me.num2 = num2
        End Sub
        Sub Print()
            Console.WriteLine("Num1 : {0}", Me.num1)
            Console.WriteLine("Num2 : {0}", Me.num2)
        End Sub
    End Class
    Sub Main()
        Dim obj As New Sample(10, 20)
        obj.Print()
    End Sub
End Module
	
Output:
Num1 : 10
Num2 : 20
Explanation:

We created a Module1 module in the above program that contains a Sample Class. In the Sample class, the two num1 and num2 data members were created.

Sub New(ByVal num1 As Integer, ByVal num2 As Integer)
    Me.num1 = num1
    Me.num2 = num2
End Sub

We initialized the data members using local variables in the above function constructor. Here, to distinguish the data member and the local variable, we used the Me object. With Me objects, data members are accessed.

We built the Print() method here to print data member values on the console screen.

Finally, the Main() method was developed, and the Main() method is the program's entry point. Here, we created the Sample class object and then called the method Print().


No Sidebar ads