×

VB.Net Programs

VB.Net program to demonstrate the 'Me' object

By Nidhi Last Updated : November 11, 2024

'Me' object in VB.Net

Here, we will access the data member of the class using the "Me" object inside the class. The "Me" object is used point current object in vb.net.

Program/Source Code:

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

VB.Net code to demonstrate the example of 'Me' object

'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
Press any key to continue . . .

Explanation:

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

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

In the above constructor, we initialized the data members using local variables. Here, we used the Me object to differentiate the data member and local variable. Data members are accessed with Me objects.

Here, we created the Print() method to print values of data members on the console screen.

At last, we created the Main() method, the Main() method is the entry point for the program. Here, we created the object of the Sample class and then called the Print() method.

VB.Net Basic Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.