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.ToString

Nathan Reinauer
Nathan Reinauer
2,097 Points

Trying to add "ToString" method but nothing is working

I've added "ToString()" pretty much everywhere in this code and I get a variety of errors. For example, sometimes the prompt asks if I've "overridden" the method yet, at which point the compiler tells me I can't actually override that method.

I think part of my confusion is that it's asking me to add a ToString method, but ToString is already a method. Does it want me to create a NEW method using ToString, or add ToString() to a different method somehow?

My code now is just a mess of different things I did through trial and error.

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

        public VocabularyWord(string word)
        {
            Word = word.ToString();
            return Word;
        }
    }
}

1 Answer

Toni Dzalto
Toni Dzalto
21,667 Points

Hi

They are basically asking you to override the method ToString, and return the word that is set "Word".

public override string ToString() { return Word; }