To create a single row result ...
var stringCollection = new[] { "House", "Car", "house", "Dog", "Cat" }; var result = stringCollection.Cast<string>().GroupBy( k => k, StringComparer.InvariantCultureIgnoreCase) .Select(v => v.Key + " -->" + v.Count()) .Aggregate((l,r)=>l+" " + r);
To put each value on a different line ...
var stringCollection = new[] { "House", "Car", "house", "Dog", "Cat" }; var result = stringCollection.Cast<string>().GroupBy( k => k, StringComparer.InvariantCultureIgnoreCase); foreach (var value in result) Console.WriteLine("{0} --> {1}", value.Key, value.Count());
Matthew whited
source share