Word Frequency Dictionary
This exercise practices keyed lookup, normalization, and collection expressions.
How it works
Count normalized words with Dictionary<TKey,TValue>.
GetValueOrDefault provides zero for unseen words before the count is incremented.
Runnable C# example
Program.cs
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
var counts = new Dictionary<string, int>();
foreach (string word in "C# is fun and C# is fast".ToLower().Split(' '))
counts[word] = counts.GetValueOrDefault(word) + 1;
Console.WriteLine(counts["c#"]);
}
}
2Practice with the debugger
Set a breakpoint on an important assignment or condition, click Debug, and inspect the local values before stepping to the next line.