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# Intermediate C# System.Object Object.GetHashCode

Some help?

I didnt really understand how Im supposed to pass this unto an int when its a string. Some help would be appreaciated.

2 Answers

Hey there Fabiola Barrientos ,

You'll want to use the override modifier for this method that has an expected return type of int.

Hope this helps!

Ive already tried that, but when I do I get the message: "VocabularyWord.cs(32,35): error CS0428: Cannot convert method group GetHashCode' to non-delegate typeint'. Consider using parentheses to invoke the method" Whenever i try to use "(int)" on "VocabularyWord" I get the same message, and when I use it on "GetHashCode()" I get the message: "VocabularyWord.cs(32,34): error CS1001: Unexpected symbol `(', expecting identifier"

Here is the code

using System;
namespace Treehouse.CodeChallenges
{
    public class VocabularyWord
    {
        public string Word { get; private set; }

        public VocabularyWord(string word)
        {
            Word = word;
        }

        public override string ToString()
        {
            return Word;
        }

        public override bool Equals(object obj)
        {
            if(!(obj is VocabularyWord))
            {
                return false;
            }

            var that = obj as VocabularyWord;

            return this.Word.Equals(that.Word);
        }

        public override int GetHashCode()
        {
            return VocabularyWord.GetHashCode();
        }
    }
}
Steven Parker
Steven Parker
231,198 Points

You're very close, but "VocabularyWord" is the name of the class itself. The name of the attribute variable where the string is stored is just "Word":

            return Word.GetHashCode();