C# Sharp Exercises: Display the characters and frequency of character from giving string
C# Sharp LINQ : Exercise-5 with Solution
Write a program in C# Sharp to display the characters and frequency of character from giving string.
Sample Solution:-
C# Sharp Code:
using System;
using System.Linq;
using System.Collections.Generic;
class LinqExercise5
{
static void Main(string[] args)
{
string str;
Console.Write("\nLINQ : Display the characters and frequency of character from giving string : ");
Console.Write("\n----------------------------------------------------------------------------\n");
Console.Write("Input the string : ");
str= Console.ReadLine();
Console.Write("\n");
var FreQ = from x in str
group x by x into y
select y;
Console.Write("The frequency of the characters are :\n");
foreach(var ArrEle in FreQ)
{
Console.WriteLine("Character "+ArrEle.Key + ": " + ArrEle.Count()+" times");
}
}
}
Sample Output:
LINQ : Display the characters and frequency of character from giving string : ---------------------------------------------------------------------------- Input the string : w3resource The frequency of the characters are : Character w: 1 times Character 3: 1 times Character r: 2 times Character e: 2 times Character s: 1 times Character o: 1 times Character u: 1 times Character c: 1 times
Pictorial Presentation:
Flowchart:
C# Sharp Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a program in C# Sharp to display the number and frequency of number from given array.
Next: Write a program in C# Sharp to display the name of the days of a week.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework