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

Haldon Francis
Haldon Francis
619 Points

using System; class Program { // YOUR CODE HERE: Define a Quote method! static string Quote(string phrase) {

I would like to see the solution to this Challenge, please?

Program.cs
using System;

class Program
{

    // YOUR CODE HERE: Define a Quote method!
    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.\""));
    }

}

4 Answers

Haldon Francis
Haldon Francis
619 Points

Thank you, this helped. The video I watched on the topic did not explain concatenation like this. I'm also a beginner so an example for me would be much clearer than worked. but thanks much for your patience.

Steven Parker
Steven Parker
231,268 Points

Haldon Francis — Did you mean to mark your own comment as "best answer"? :see_no_evil:
(You can still change it)

Steven Parker
Steven Parker
231,268 Points

You're already close, the method declaration including types, access, parameter, are all good.

Now instead of returning the parameter is it is, use concatenation (+) to add a quote character before and after it.

But do all your work in the new function, do not modify the provided code in the Main section. The challenge will call your function directly to test it with different data.

Steven Parker
Steven Parker
231,268 Points

To represent a regular quote, you'd need to put it inside single quotes, like this :point_right: '"'
Then, you'd need to concatenate one of those both before and after the phrase (making a "sandwich").

Haldon Francis
Haldon Francis
619 Points

I am not quite sure I understand.

****return (phrase " " + " ")

Do you actually mean like this?

Haldon Francis
Haldon Francis
619 Points

Can you please leave an example. This would help much more speedily than an explanation.

Ex. return (“ “ + phrase + “ “)

Steven Parker
Steven Parker
231,268 Points

You've nearly got it there, except you're adding spaces (" ") and you need quote marks ('"').