Home »
        VB.Net »
        VB.Net Programs
    
    VB.Net program to demonstrate Set and Get properties with structure
    
    
    
    
	    
		    By Nidhi Last Updated : November 11, 2024
	    
    
    
    Set and Get properties with structure in VB.Net
    Here, we will create a structure and implement Set and Get properties to set and get values of members of the structure and then we print the values on the console screen.
        
    Program/Source Code:
    The source code to demonstrate Set and Get properties with structure is given below. The given program is compiled and executed successfully.
    VB.Net code to demonstrate the Set and Get properties with structure
'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 = 1000
        Stu.StudentName = "Karan Malhotra"
        Console.WriteLine("Student Id  : {0}", Stu.StudentID)
        Console.WriteLine("Student Name: {0}", Stu.StudentName)
    End Sub
End Module
Output
Student Id  : 1000
Student Name: Karan Malhotra
Press any key to continue . . .
    Explanation
    In the above program, we created a structure 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 structure and then set the values of data members and then print the student information on the console screen.
    VB.Net Structure Programs »
    
    
    
    
   
    
  
    Advertisement
    
    
    
  
  
    Advertisement