c# program to count the occurrences of each character

c# program to count the occurrences of each character
using System;
using System.Linq;

public class Program
{
public static void Main()
{
string str= "C# program to count the occurrences of each character".ToLower();
var charcount = (from c in str
                    group c by c into g
                    select new
                    {
                        c = g.Key,
                        count = g.Count(),
                    }).OrderByDescending(c => c.count);
foreach (var data in charcount)
{
                   Console.WriteLine(data.c + ":" + data.count);
}
}
}

Post a Comment

0 Comments