LINQ Distinct operator, ignore case?
StringComparer
does what you need:
List<string> list = new List<string>() {
"One", "Two", "Three", "three", "Four", "Five" };
var distinctList = list.Distinct(
StringComparer.CurrentCultureIgnoreCase).ToList();
(or invariant / ordinal / etc depending on the data you are comparing)
[See Marc Gravells answer if you want the most concise approach]
After some investigation and good feedback from Bradley Grainger I've implemented the following IEqualityComparer. It suports a case insensitive Distinct() statement (just pass an instance of this to the Distinct operator) :
class IgnoreCaseComparer : IEqualityComparer<string> { public CaseInsensitiveComparer myComparer; public IgnoreCaseComparer() { myComparer = CaseInsensitiveComparer.DefaultInvariant; } public IgnoreCaseComparer(CultureInfo myCulture) { myComparer = new CaseInsensitiveComparer(myCulture); } #region IEqualityComparer<string> Members public bool Equals(string x, string y) { if (myComparer.Compare(x, y) == 0) { return true; } else { return false; } } public int GetHashCode(string obj) { return obj.ToLower().GetHashCode(); } #endregion }