Tally distinct items in a list using the GroupBy operator
String[] items = { "cat", "pear", "apple", "cat", "banana", "pear", "pear", "apple" };
Dictionary<String, int> tallies = items.GroupBy(k => k)
.ToDictionary(k => k.Key, e => e.Count());
This results in the following dictionary in 'tallies':
{ "cat", 2 }
{ "pear", 3 }
{ "apple", 2 }
{ "banana", 1 }
Join an array of strings
String[] rgs = {"the", "quick", "brown", "fox" };
String s = rgs.Aggregate((av, e) => av + " " + e);
// s == "the quick brown fox", same as:
s = String.Join(" ", rgs);
Remove all spaces from a string
Note that all of the Linq IEnumerable<T> extensions work directly on a String, processing it as an array of characters.
String s = "four score and seven years ago";
s = new String(s.Where(e => e != ' ').ToArray());
// s == "fourscoreandsevenyearsago"