Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Collections Sets and Dictionaries Using Dictionaries

don't understand the question! please help!!

the question.. " Create a method named WordsWithCountGreaterThan that takes an integer as a parameter. The method should return a dictionary of all of the words that have a count greater than the parameter passed in. The dictionary should contain the word and the word's count. " i keep the bummer error message. i'm not getting the question

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);
            }
        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,248 Points

It looks like you got a good start.

Your declaration has the right calling signature (argument, return type). So now you need a pair of braces for the body code to go in. Inside that, you'll create a new dictionary variable, and a loop that essentially copies the WordCount to the new dictionary, but it will skip entries that don't "have a count greater than the parameter passed in". Finally, you will return that new dictionary.

But also check that the code you created for AddWord is still the way it was when you passed task 1. Right now it looks like it may have been modified in a way that will cause the re-test to fail.