﻿ C# Sharp Exercises: Create a nested structure and store data in an array - w3resource

# C# Sharp Exercises: Create a nested structure and store data in an array

## C# Sharp STRUCTURE: Exercise-3 with Solution

Write a program in C# Sharp to create a nested structure to store two data for an employee in an array.

Sample Solution:-

C# Sharp Code:

``````using System;
class strucExer3
{
//employee is a structure of members eName and dtObirth
struct employee
{
public string eName;
public dtObirth Date;
}
//dtObirth is a nested structure of employee
struct dtObirth
{
public int Day;
public int Month;
public int Year;
}
static void Main(string[] args)
{

int dd=0, mm=0, yy=0;
int total = 2;
Console.Write("\n\nCreate a nested structure and store data in an array :\n");
Console.Write("-------------------------------------------------------\n");
employee[] emp = new employee[total];

for (int i = 0; i < total; i++)
{
Console.Write("Name of the employee : ");
emp[i].eName = nm;

Console.Write("Input day of the birth : ");
emp[i].Date.Day = dd;

Console.Write("Input month of the birth : ");
emp[i].Date.Month = mm;

Console.Write("Input year for the birth : ");
Console.WriteLine();
emp[i].Date.Year = yy;
}
}
}
```
```

Sample Output:

```Create a nested structure and store data in an array :
-------------------------------------------------------
Name of the employee : H.Rana
Input day of the birth : 04
Input month of the birth : 05
Input year for the birth : 1787

Name of the employee : D.Das
Input day of the birth : 08
Input month of the birth : 04
Input year for the birth : 1784
```

Flowchart:

C# Sharp Code Editor: