/// <summary> /// Creates an alphabetized list of words + word counts from the unique words. /// </summary> /// <returns></returns> private List <UniqueWord> AlphabetizedWordCountList() { UniqueWord uniqueWord; int wordCount = 0; List <UniqueWord> wordCountList = new List <UniqueWord>(); foreach (string word in AlphabetizedWords) { wordCounts.TryGetValue(word, out wordCount); uniqueWord = new UniqueWord(word, wordCount); wordCountList.Add(uniqueWord); } return(wordCountList); }
static void Main(string[] args) { List <UniqueWord> uniqueWords = new List <UniqueWord>(); foreach (string word in File.ReadAllLines("words.txt")) { UniqueWord uniqueWord = uniqueWords.Where(x => x.Word == word).FirstOrDefault(); if (uniqueWord != null) { uniqueWord.Occurrence++; } else { uniqueWords.Add(new UniqueWord(word)); } } uniqueWords = uniqueWords.OrderByDescending(x => x.Word.Length).ToList(); }
static void Main(string[] args) { List <string> wordsToCut = File.ReadAllLines("text2.txt").Distinct().ToList(); List <UniqueWord> uniqueWords = new List <UniqueWord>(); foreach (string word in File.ReadAllLines("text1.txt")) { if (wordsToCut.Contains(word) == false) { UniqueWord uniqueWord = uniqueWords.Where(x => x.Word == word).FirstOrDefault(); if (uniqueWord != null) { uniqueWord.Occurrence++; } else { uniqueWords.Add(new UniqueWord(word)); } } } uniqueWords = uniqueWords.OrderByDescending(x => x.Word.Length).Take(10).ToList(); }
/// <summary> /// Determines if two unique words are materially equivalent. /// </summary> /// <param name="otherWord">The other unique word to check for equivalence</param> /// <returns>True if they contain the same word with the same word count.</returns> public bool Equals(UniqueWord otherWord) { return(Word == otherWord.Word && Count == otherWord.Count); }