C# C# Collections Sets and Dictionaries Using Dictionaries

Mohammad Siddeq
Mohammad Siddeq
10,968 Points

Create a method named WordsWithCountGreaterThan that takes an integer as a parameter. The method should return a diction

what is wrong

LexicalAnalysis.cs
using System.Collections.Generic;

namespace Treehouse.CodeChallenges
{
    public class LexicalAnalysis
    {
        public Dictionary<string, int> WordsWithCountGreaterThan(int i)
        public Dictionary<string, int> WordCount = new Dictionary<string, int>();

        public void AddWord(string word)
        foreach(var word in WordCount.Keys)
        {
              if (WordCount.ContainsKey(word))
            {
                WordCount[word]++;
            }
            else
            {
                WordCount.Add(word, 1);
            }
             return WordCount;
        }

    }
}

1 Answer

Steven Parker
Steven Parker
168,105 Points

I see a few issues:

  • the braces that should enclose the method body are missing
  • this method adds a single "word" to the dictionary, it won't need a loop
  • this is a void method, so it won't return anythying