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 trialTiago Ramos
2,380 PointsHow can I use .ToString() in this situation?
Hello guys, shouldn't I be able to simply call the .ToString() method for it to return the Word variable in a "string"?
using System;
namespace Treehouse.CodeChallenges
{
class VocabularyWord
{
public string Word { get; private set; }
public override VocabularyWord(string word)
{
Word = word;
return Word.ToString();
}
}
}
1 Answer
Dale Severude
Full Stack JavaScript Techdegree Graduate 71,350 PointsHi Tiago,
You don't need to call .ToString
on Word
because Word
is already a string. Also you do not want to override the VocabularyWord
constructor because there is no need to change the constructor.
You do need to override the .ToString
method and then return Word
inside it.
Tiago Ramos
2,380 PointsTiago Ramos
2,380 PointsThank you Dale, great help! :)