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.






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





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.