Count word frequency with Dictionary<string,int>.
Ready — edit the code above and click Run.
using System;
using System.Collections.Generic;
class Program {
static void Main() {
string[] words = { "a", "b", "a", "c", "b", "a" };
var freq = new Dictionary<string, int>();
foreach (var w in words)
freq[w] = freq.TryGetValue(w, out var c) ? c + 1 : 1;
Console.WriteLine(freq["a"]);
}
}
Try solving on your own first, then reveal the official answer.
TryGetValue avoids double lookup—Dictionary interview best practice.