Mid
From PDF
Coding Scenarios
C# Coding Interview
Count occurrence of each word?
string sentence = "dotnet is great dotnet is powerful";
string[] words = sentence.Split(' ');
Dictionary<string, int> map = new Dictionary<string, int>();
foreach (string word in words)
map[word] = map.ContainsKey(word) ? map[word] + 1 : 1;Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png