Last active
November 1, 2017 15:09
-
-
Save jfcarr/7672c080a0feeb42a6a35150951f38b8 to your computer and use it in GitHub Desktop.
Remove duplicates from a list collection - implemented as a method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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