Example – list of people

The second example regarding the List class shows how to use this data structure to create a very simple database of people. For each of them, a name, a country, and an age are stored. When the program is launched, some data of people are added to the list. Then, the data is sorted (using the LINQ expression) and presented in the console.

Let's start with declaration of the Person class, as shown in the following code:

public class Person 
{ 
    public string Name { get; set; } 
    public int Age { get; set; } 
    public CountryEnum Country { get; set; } 
} 

The class contains three public properties, namely Name, Age, and Country. It is worth noting that the Country property is of the CountryEnum type, which defines three constants, ...

Get C# Data Structures and Algorithms now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.