C# Program to Demonstrate the Array of Structures Last Updated : 29 Oct, 2021 Comments Improve Suggest changes Like Article Like Report An array of structures means each array index contains structure as a value. In this article, we will create the array of structure and access structure members using an array with a specific index. Syntax array[index].Structure(Details); where index specifies the particular position to be inserted and details are the values in the structure Example: Input: Insert three values in an array Student[] student = { new Student(), new Student(), new Student() }; student[0].SetStudent(1, "ojaswi", 20); student[1].SetStudent(2, "rohith", 21); student[2].SetStudent(3, "rohith", 21); Output: (1, "ojaswi", 20) (2, "rohith", 21) (3, "rohith", 21) Approach: Declare three variables id , name and age.Set the details in the SetStudent() method.Create array of structure for three students.Pass the structure to array index for three students separately.Display the students by calling DisplayStudent() method Example: C# // C# program to display the array of structure using System; public struct Employee { // Declare three variables // id, name and age public int Id; public string Name; public int Age; // Set the employee details public void SetEmployee(int id, string name, int age) { Id = id; Name = name; Age = age; } // Display employee details public void DisplayEmployee() { Console.WriteLine("Employee:"); Console.WriteLine("\tId : " + Id); Console.WriteLine("\tName : " + Name); Console.WriteLine("\tAge : " + Age); Console.WriteLine("\n"); } } class GFG{ // Driver code static void Main(string[] args) { // Create array of structure Employee[] emp = { new Employee(), new Employee(), new Employee() }; // Pass the array indexes with values as structures emp[0].SetEmployee(1, "Ojaswi", 20); emp[1].SetEmployee(2, "Rohit", 21); emp[2].SetEmployee(3, "Mohit", 23); // Call the display method emp[0].DisplayEmployee(); emp[1].DisplayEmployee(); emp[2].DisplayEmployee(); } } Output: Employee: Id : 1 Name : Ojaswi Age : 20 Employee: Id : 2 Name : Rohit Age : 21 Employee: Id : 3 Name : Mohit Age : 23 Comment More infoAdvertise with us Next Article C# Program to Demonstrate the Array of Structures gottumukkala_sivanagulu Follow Improve Article Tags : C# CSharp-Arrays CSharp-programs Similar Reads C# Program to Demonstrate the Static Constructor in Structure A Structure is a well-defined data structure that can hold elements of multiple data types. It is similar to a class because both are user-defined data types and both contain a bunch of different data types. You can also use pre-defined data types. However, sometimes the user might be in need to def 2 min read How to Declare and Initialize an Array of Pointers to a Structure in C? Prerequisite: Structure in CArray in C In C language, arrays are made to store similar types of data in contiguous memory locations. We can make arrays of either primitive data types, like int, char, or float, or user-defined data types like Structures and Unions. We can also make arrays of pointers 8 min read C++ Program to Implement Stack using array Stack is the fundamental data structure that can operates the under the Last In, First Out (LIFO) principle. This means that the last element added to the stack is the first one to be removed. Implementing the stack using the array is one of the most straightforward methods in the terms of the both 4 min read Array of Structures vs Array within a Structure in C++ In C++, an array of structure and an array within structure are used frequently used for data storage. Although they sound similar, they work pretty differently from each other. In this article, we will discuss the key differences between an array of structures and an array within structures and cla 4 min read How to declare a Two Dimensional Array of pointers in C? A Two Dimensional array of pointers is an array that has variables of pointer type. This means that the variables stored in the 2D array are such that each variable points to a particular address of some other element. How to create a 2D array of pointers: A 2D array of pointers can be created follo 3 min read Like