Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the structure within a structure
Here, we are going to demonstrate the structure within a structure in VB.Net.
Submitted by Nidhi, on December 20, 2020
Here, we will create a Student structure that contains a nested structure StuInfo. Here, we set the value of nested structure and then print values on the console screen.
Program/Source Code:
The source code to demonstrate structure within the structure is given below. The given program is compiled and executed successfully.
'VB.Net program to demonstrate structure within a structure.
Module Module1
Structure Student
Public id As Integer
Public fee As Integer
Structure StuInfo
Public name As String
Public address As String
End Structure
End Structure
Sub Main()
Dim stu As New Student()
stu.id = 101
stu.fee = 2000
Dim info As New Student.StuInfo()
info.name = "Shaurya"
info.address = "New Delhi"
Console.WriteLine("Student Information: ")
Console.WriteLine(vbTab & "Id : " & stu.id)
Console.WriteLine(vbTab & "Name : " & info.name)
Console.WriteLine(vbTab & "Fee : " & stu.fee)
Console.WriteLine(vbTab & "Address : " & info.name)
End Sub
End Module
Output:
Student Information:
Id : 101
Name : Shaurya
Fee : 2000
Address : Shaurya
Press any key to continue . . .
Explanation:
In the above program, we created a module Module1. Here, we created a Structure Student that contains data members' id, fees. The Student structure also contains a nested structure StuInfo. The StuInfo structure two public members' name and address.
In the Main() function, we initialized the Student and StuInfo structure and then printed the values of members on the console screen.
TOP Interview Coding Problems/Challenges