Skip to Content
C# Data Structures and Algorithms
book

C# Data Structures and Algorithms

by Marcin Jamro
April 2018
Intermediate to advanced content levelIntermediate to advanced
292 pages
6h 44m
English
Packt Publishing
Content preview from C# Data Structures and Algorithms

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Data Structures and Algorithms in C#

Beginning Data Structures and Algorithms in C#

Marcin Jamro

Publisher Resources

ISBN: 9781788833738Supplemental Content