Tech Study

Write a program in C# to display the characters and frequency of character from given string in LINQ Query

Introduction

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability.

using System;
using System.Linq;
using System.Collections.Generic;
 
class LinqExercise
{
    static void Main(string[] args)
    {
        string str;
 
        Console.WriteLine("Input the string : ");
        str = Console.ReadLine();        
 
        var Frequency = from x in str
                   group x by x into y
                   select y;
        Console.Write("The frequency of the characters are :\n");
        foreach (var Arr in Frequency)
        {
            Console.WriteLine("Character " + Arr.Key + ": " + Arr.Count() + " times");
        }
        Console.ReadLine();
    }
}

Result

Write a program in C# to display the characters and frequency of character from given string in LINQ Query
Write a program in C# to display the characters and frequency of character from given string in LINQ Query

TaggedWrite a program in C# to display the characters and frequency of character from given string in LINQ Query

Python Examples

Introduction: Python Examples are the basic programming concepts of python like python syntax,python data types,,python operators,python if else,python comments etc.. …

Read more

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more