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 – removing duplicates

As an example, you will create a simple application that removes duplicates from the list of names. Of course, the comparison of names should be case-insensitive, thus it is not allowed to have both "Marcin" and "marcin" in the same collection.

To see how to perform this goal, let's add the following code as the body of the Main method in the Program class:

List<string> names = new List<string>() 
{ 
    "Marcin", 
    "Mary", 
    "James", 
    "Albert", 
    "Lily", 
    "Emily", 
    "marcin", 
    "James", 
    "Jane" 
}; 
SortedSet<string> sorted = new SortedSet<string>( 
    names, 
    Comparer<string>.Create((a, b) =>  
        a.ToLower().CompareTo(b.ToLower()))); 
foreach (string name in sorted) 
{ 
    Console.WriteLine(name); 
} 

At the beginning, a list of names is created ...

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