Code the AddWord method such that, WordCount will contain the number of times the AddWord method has been called with a given word. For example, if AddWord is called twice with the word "rock" then WordCount["rock"] will be 2.
Example: Code the AddWord method such that, WordCount will contain the number of times the AddWord method has been called with a given word. For example, if AddWord is called twice with the word "rock" then WordCount["rock"] will be 2.
using System.Collections.Generic;
namespace Treehouse.CodeChallenges
{
public class LexicalAnalysis
{
public Dictionary<string, int> WordCount = new Dictionary<string, int>();
public void AddWord(string word)
{
bool check = false;
foreach (string entry in WordCount.Keys)
{
if (entry == word)
{
check = true;
break;
}
}
if (check) {
WordCount[word] += 1;
} else {
WordCount.Add(word, 1);
}
}
}
}