8

I have list, how can I get distinct values?

IList<string> words = new List<string> { "A", "b", "a" };
var distinctWords = words.Distinct(StringComparison.OrdinalIgnoreCase);

this gives me error: Distinct has some invalid arguments.

michael
  • 647
  • 2
  • 7
  • 17
  • possible duplicate of [LINQ Distinct operator, ignore case?](http://stackoverflow.com/questions/283063/linq-distinct-operator-ignore-case) – huMpty duMpty Apr 17 '14 at 17:10

1 Answers1

14

You need: StringComparer.OrdinalIgnoreCase not StringComparison.OrdinalIgnoreCase

IList<string> words = new List<string> { "A", "b", "a" };
var distinctWords = words.Distinct(StringComparer.OrdinalIgnoreCase);
Habib
  • 219,104
  • 29
  • 407
  • 436