April 2018
Intermediate to advanced
292 pages
6h 44m
English
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 ...