using System.Collections.Generic;
public static void Main()
var wordCollection = GetWordsFrequencyCount("My bike and my book");
foreach (var item in wordCollection)
Console.WriteLine("\"{0}\": {1}",item.Key,item.Value);
var wordlenghtCollection = GetWordsLengthFrequencyCount("My bike and my book");
foreach (var item in wordlenghtCollection)
Console.WriteLine("{0}: {1}",item.Key,item.Value);
static Dictionary <string, int> GetWordsFrequencyCount(string text)
Dictionary<string, int> wordCollection = new Dictionary<string, int>();
var words = text.ToLower().Split(' ');
foreach (var word in words)
if (wordCollection.ContainsKey(word))
wordCollection.Add(word, 1);
static Dictionary<int, int> GetWordsLengthFrequencyCount(string text)
Dictionary<int, int> wordLenghtCollection = new Dictionary<int, int>();
var words = text.ToLower().Split(' ');
foreach (var word in words)
wordLenght = word.Length;
if (wordLenghtCollection.ContainsKey(wordLenght))
wordLenghtCollection[wordLenght]++;
wordLenghtCollection.Add(wordLenght, 1);
return wordLenghtCollection;