Home >>VB.Net Built-in Functions >VB.Net Program to demonstrate Set and Get Properties with Structure

VB.Net Program to demonstrate Set and Get Properties with Structure

Write a VB.Net Program to demonstrate Set and Get Properties with Structure

Here, we create a structure and add the Set and Get properties to set and get the values of the members of the structure and then print the values on the screen of the console.

Program :

Below is the source code to show Set and Get Properties with Structure. The program given is compiled and successfully executed.

'VB.net program to demonstrate

'Set and Get properties with structure.


Structure 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 Structure
Module Module1
    Sub Main()
        Dim Stu As New Student()
        Stu.StudentID = 1100
        Stu.StudentName = "Manish "
        Console.WriteLine("Student Id  : {0}", Stu.StudentID)
        Console.WriteLine("Student Name: {0}", Stu.StudentName)
    End Sub
End Module
	
Output:
Student Id : 1100
Student Name: Manish

Explanation:

We built a Student class structure in the above program that contains Id, Name, two data members. 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 program entry point is the Main() method. And, we've built a Student structure object, set the data member values, and then print the student details on the console screen.


No Sidebar ads