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 

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

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.