Structs with Other Data Structures
Since structs are essentially data types, we can use them for creating Arrays and Lists as well:
index.cs
In a List or an Array, we would access a Student object's field using the following syntax:
index.cs
For-example:
index.cs
We can also loop through these arrays or lists to assign or access data. For-example the following code loops through a List of Students
objects and calculates the average age:
index.cs
It is clear that here the Student
struct acts like a data type. We can also use Student
as a dictionary value as well. Following is an example of using Struct as a value in a dictionary:
index.cs
Everything was clear?
Course Content
C# Beyond Basics
C# Beyond Basics
Structs with Other Data Structures
Since structs are essentially data types, we can use them for creating Arrays and Lists as well:
index.cs
In a List or an Array, we would access a Student object's field using the following syntax:
index.cs
For-example:
index.cs
We can also loop through these arrays or lists to assign or access data. For-example the following code loops through a List of Students
objects and calculates the average age:
index.cs
It is clear that here the Student
struct acts like a data type. We can also use Student
as a dictionary value as well. Following is an example of using Struct as a value in a dictionary:
index.cs
Everything was clear?