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# Basics Strings Escape Sequences

Need Assistance Finding How This Challenge Works

This challenge is really hard for me, and I'm not sure what to do at this point. Can someone please help?

Program.cs
using System;

class Program
{

    static string Quote(string phrase)
    {
        return $"\" {phrase} \"";
    }

    static void Main(string[] args)
    {
        // Quote by Maya Angelou.
        Console.WriteLine(Quote("When you learn, teach. When you get, give."));
        // Quote by Benjamin Franklin.
        Console.WriteLine(Quote("No gains without pains."));
    }

}

I was able to find the solution here: https://teamtreehouse.com/community/when-clicking-preview-for-the-code-challenge-i-get-a-completely-different-result-from-what-my-code-should-display

And now my code is updated to

using System;

class Program
{

    static string Quote(string phrase)
    {
        return('"' + phrase + '"');
    }

    static void Main(string[] args)
    {
        // Quote by Maya Angelou.
        Console.WriteLine(Quote("When you learn, teach. When you get, give."));
        // Quote by Benjamin Franklin.
        Console.WriteLine(Quote("No gains without pains."));
    }

}

But I do not recall learning anything about using single quotes ` for my code. The hint was received when the compiler failed and produced the Patrick quote. If that's as design- frankly that's disheartening. Can someone please explain to me how is this the correct answer?

1 Answer

Steven Parker
Steven Parker
231,269 Points

Single quotes indicate a literal character, double quotes are for litleral strings. The concatenation operator works with either (or both).

Your interpolated template would have also worked if you omitted the extra spaces inside the quotes:

        return $"\"{phrase}\"";

Dang! Okay, I understand now. Thank you for your help!