using System.Text.RegularExpressions;
using System.Collections.Generic;
public static void Main()
Dictionary<string, int> wordCount = GetWordsFrequencyCount("My bike and my book");
string frequency = string.Join(", ", wordCount.Select(x => "\"" + x.Key + "\"" + ": " + x.Value).ToArray());
Console.WriteLine(frequency);
Dictionary<int, int> wordLength = GetWordsFrequencyCountLength("My bike and my book");
string fLength = string.Join(", ", wordLength.Select(x => x.Key + ": " + x.Value).ToArray());
Console.WriteLine(fLength);
public static Dictionary<string, int> GetWordsFrequencyCount(string text)
var dict = new Dictionary<string, int>();
string[] arr = text.ToLower().Split(' ');
foreach(string word in arr)
if (dict.ContainsKey(word))
public static Dictionary<int, int> GetWordsFrequencyCountLength(string text)
var dict = new Dictionary<int, int>();
string[] arr = text.ToLower().Split(' ');
for (int i = 0; i < arr.Length; i++)
strLength = arr[i].Length;
if (dict.TryGetValue(strLength, out val))
dict[strLength] = val + 1;