public Dictionary(String filename) { try { words = new Dictionary<string, List<string>>(); var FS = new FileStream(filename, FileMode.Open); var SR = new StreamReader(FS); string file = SR.ReadToEnd(); fileName = filename; var filesplit = file.Split('\n').Select(s => s.Trim()).ToList(); foreach (string s in filesplit) { if (s.Length < 3) continue; string sortedKey = sortString(s); if (words.ContainsKey(sortedKey)) { List<string> existing = words[sortedKey]; if (existing.Contains(s) == false) existing.Add(s); words[sortedKey] = existing; } else { var newlist = new List<string>(); newlist.Add(s); words[sortedKey] = newlist; } } SR.Close(); FS.Close(); } catch { MessageBox.Show("Error adding dictionary file:" + filename); } }
private Dictionary<char, int> getWordCount(String charlist) { var pch = new Dictionary<char, int>(); foreach (char c in charlist) { if (pch.ContainsKey(c) == false) pch[c] = 0; pch[c] = pch[c] + 1; } return pch; }