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.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. class LinqExercise
  6. {
  7. static void Main(string[] args)
  8. {
  9. string str;
  10.  
  11. Console.WriteLine("Input the string : ");
  12. str = Console.ReadLine();
  13.  
  14. var Frequency = from x in str
  15. group x by x into y
  16. select y;
  17. Console.Write("The frequency of the characters are :\n");
  18. foreach (var Arr in Frequency)
  19. {
  20. Console.WriteLine("Character " + Arr.Key + ": " + Arr.Count() + " times");
  21. }
  22. Console.ReadLine();
  23. }
  24. }

Result

C# language techstudy.org

     





Related Topics




Popular Posts