O'Reilly logo

C# Data Structures and Algorithms by Marcin Jamro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required