Time for action – removing duplicate song IDs from the list

Follow the given steps: .

  1. Copy the following code snippet as a query to LINQPad:
    string[] songIds = {"Song#1", "Song#2", "Song#2", "Song#2", "Song#3", "Song#1"};
    //This will work as strings implement IComparable
    var uniqueSongIds = songIds.Distinct();
    //Iterating through the list of unique song IDs
    foreach (var songId in uniqueSongIds)
    Console.WriteLine(songId);
  2. Run the query. You should see the following output:
    Time for action – removing duplicate song IDs from the list

Assume, Distinct() as a filter that removes duplicate items and returns a collection with only unique items:

However, if that's not the case, an IEqualityComparer is passed, which ...

Get .NET 4.0 Generics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.