// Add a given word to their respective lists to calculate basic information about the location of a given word in relation to // the previous or next word public void AddNeighbouringWord(string word, bool preceding) { NeighbouringWordInformation info = new NeighbouringWordInformation(word); if (preceding) { AddToSet(ref _previousWords, info); } else { AddToSet(ref _nextWords, info); } }
// Add a neighbouring word to the set passed in as a parameter private void AddToSet(ref List <NeighbouringWordInformation> set, NeighbouringWordInformation info) { bool found = false; foreach (NeighbouringWordInformation wordInfo in set) { if (wordInfo == info) { wordInfo.Count++; found = true; break; } } if (!found) { set.Add(info); } }