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 – address book

This example uses the SortedList class to create a very simple address book, which is sorted by names of people. For each person, the following data is stored: Name, Age, and Country. The declaration of the Person class is shown in the following code:

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

A value of the Country property can be set to one of the constants from CountryEnum:

public enum CountryEnum 
{ 
    PL, 
    UK, 
    DE 
} 

The most interesting part of code is placed in the Main method within the Program class. Here, a new instance of the SortedList generic class is created, specifying types for keys and values, namely string and Person, as ...

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