The
GroupBy
extension method and
Count
extension methods of IEnumerable interface can be used as shown below:
void Main()
{
string str="basheer";
List<string> charCounts = str.GroupBy (ch => ch).Select (
item => item.Key + "=" + item.Count().ToString()).ToList();
foreach (string s in charCounts)
{
Console.WriteLine (s);
}
}