Skip to content

Instantly share code, notes, and snippets.

@jfcarr
Last active November 1, 2017 15:09
Show Gist options
  • Save jfcarr/7672c080a0feeb42a6a35150951f38b8 to your computer and use it in GitHub Desktop.
Save jfcarr/7672c080a0feeb42a6a35150951f38b8 to your computer and use it in GitHub Desktop.
Remove duplicates from a list collection - implemented as a method
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace Console1
{
class Program
{
static IEnumerable<T> RemoveDuplicates<T>(List<T> inputList)
{
inputList.Sort();
return inputList.Distinct();
}
static void Main(string[] args)
{
var myList = new List<string> {
"John",
"Andrew",
"James",
"Jack",
"Andrew",
"Bob",
"Jack"
};
var newList = RemoveDuplicates(myList);
foreach (var item in newList)
{
Console.WriteLine(item);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment