Here's a fully commented version of the program:
using System;
using System.Collections.Generic; // needed for Dictionary class
class Program
{
static void Main()
{
string s = "by the people we the people";
string[] words = s.Split(' '); // split 's' into words using the spaces as the delimiter
// create a new Dictionary whose key is a string and value an integer
Dictionary<string, int> dict = new Dictionary<string, int>();
foreach(string word in words) // iterate through the words
{
if (dict.ContainsKey(word)) // if the word is already in the Dictionary
{
dict[word]++; // increase the value (i.e. number of occurrences) by 1
}
else // if the word is not in the Dictionary
{
dict.Add(word, 1); // add it with a value of 1
}
}
foreach(string key in dict.Keys) // iterate through the Dictionary's keys
{
Console.WriteLine("{0}={1}", key, dict[key]); // print out the key/value pairs
}
Console.ReadKey(); // keep console open till a key is pressed
}
}