Зміст курсу
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
In a List or an Array, we would access a Student object's field using the following syntax:
index
For-example:
index
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
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
Все було зрозуміло?