Home >>VB.Net Built-in Functions >VB.Net Program to Demonstrate Set and Get Properties
Here, a class will be created and Set and Get properties will be implemented to set and get the values of the data members.
Program :The source code for the Set and Get Properties demonstration is given below. The program given is compiled and successfully executed.
'VB.net program to demonstrate Set and Get properties.
Class Student
Dim Id As Integer
Dim Name As String
Public Property StudentID As Integer
Get
Return Id
End Get
Set(value As Integer)
Id = value
End Set
End Property
Public Property StudentName As String
Get
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 = 110
Stu.StudentName = "Mukesh"
Console.WriteLine("Student Id : {0}", Stu.StudentID)
Console.WriteLine("Student Name: {0}", Stu.StudentName)
End Sub
End Module
We created a Student class in the above program that contains two Id members of the data, Name. Here, we have introduced StudentId and StudentName properties to set and retrieve data member values.
After that, we built a Module1 module that contains the Main() method, and the application entry point is the Main() method. And, we've created the Student Class object, set the data member values, and then print the student details on the console screen.