I have a list like this:
var list = new List<string>() { "a", "b", "c", "a" };
As you can see I have one duplicate inside this list.
The desired output should look like this:
a (2)
b (1)
c (1)
The code which I already have looks like this:
list.GroupBy(x => x).Select(x => x.Key + "(" + x.Count() + ")").ToList().ForEach(x => list2.Add(x));
But as you can see I need a second list to get the desired output. My question now is how can I get the desired output with using only one list.