using System.Collections.Generic;
public static class Program
public static int countSubStrings( string sentence, string value )
int count = 0, minIndex = sentence.IndexOf(value, 0);
minIndex = sentence.IndexOf(value, minIndex + value.Length);
public static Dictionary<string, int> GetWordsFrequencyCount( string text )
string[] words = text.Split(' ');
Dictionary<string, int> my_dict = new Dictionary<string, int >();
for (int i=0; i< words.Length;i++)
if (!my_dict.ContainsKey(words[i]))
my_dict.Add(words[i],countSubStrings(text, words[i]));
public static Dictionary<int, int> GetWordsLengthFrequencyCount(string text){
string[] words = text.Split(' ');
Dictionary<int, int> my_dict = new Dictionary<int, int >();
Array.Sort(words, (x, y) => x.Length.CompareTo(y.Length));
for (int i=1; i < words.Length;i++)
if (words[i].Length == words[i-1].Length)
my_dict.Add(words[i-1].Length,counter);
my_dict.Add(words[i].Length,counter);
public static void Main()
string sentence = "my bike is under my tree";
Dictionary<string, int> my_dict = GetWordsFrequencyCount(sentence);
foreach( KeyValuePair<string, int > kvp in my_dict )
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
Dictionary< int, int> my_dict_2 = GetWordsLengthFrequencyCount(sentence);
foreach( KeyValuePair<int, int > kvp in my_dict_2 )
Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value);
Console.WriteLine("\ndone...");