VB.Net program to demonstrate Set and Get properties

Here, we are going to demonstrate Set and Get properties in VB.Net.
Submitted by Nidhi, on January 02, 2021

Here, we will create a class and implement Set and Get properties to set and get the values of data members.

Program/Source Code:

The source code to demonstrate Set and Get properties is given below. The given program is compiled and executed successfully.

'VB.net program to demonstrate Set and Get properties.

Class Student
    Dim Id As Integer
    Dim Name As String

    Public Property StudentID As Integer
            Return Id
        End Get
        Set(value As Integer)
            Id = value
        End Set
    End Property

    Public Property StudentName As String
            Return Name
        End Get
        Set(value As String)
            Name = value
        End Set
    End Property
End Class

Module Module1
    Sub Main()
        Dim Stu As New Student()

        Stu.StudentID = 101
        Stu.StudentName = "Baderia"

        Console.WriteLine("Student Id  : {0}", Stu.StudentID)
        Console.WriteLine("Student Name: {0}", Stu.StudentName)
    End Sub
End Module


Student Id  : 101
Student Name: Baderia
Press any key to continue . . .


In the above program, we created a class Student class that contains two data members Id, Name. Here, we implemented properties StudentId and StudentName to set and get values of data members.

After that, we created a module Module1 that contains the Main() method, the Main() method is the entry point for the program. And, we created an object of the Student class and then set the values of data members and then print the student information on the console screen.

VB.Net Basic Programs »


Comments and Discussions!

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.