ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to demonstrate the 'Me' object

Here, we are going to demonstrate the 'Me' object in VB.Net.
Submitted by Nidhi, on December 29, 2020

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



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.