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 Combining Strings

Question Broken

Program.cs
using System;

class Program
{

    static string Eat(string par1, string par2)
    {
    return ("I think apples and blueberries are tasty!"); 
    }

    static void Main(string[] args)
    {
        Console.WriteLine(Eat("apples", "blueberries"));
        Console.WriteLine(Eat("carrots", "daikon"));
    }

}

Define an Eat method that takes two string parameters. Eat should return a string in the form "I think [first parameter] and [second parameter] are tasty!" (without square brackets). For example, the call Eat("apples", "blueberries") should return "I think apples and blueberries are tasty!"

When I run any code in this section it returns something about eggs and falafel.

2 Answers

Steven Parker
Steven Parker
229,744 Points

The example output given in the question is only valid when method is called as Eat("apples", "blueberries"). If different arguments are used, the method should return a string that contains those arguments.

The code shown here only returns a literal string and ignores the arguments. It needs to be re-coded so that it builds up the string using the arguments that are passed to it. This can easily be done using String Concatenation or String Interpolation.

using System;

class Program {

// YOUR CODE HERE: Define an Eat method!
static string Eat(string foodOne, string foodTwo)
{
    return ($"I think {foodOne} and {foodTwo} are tasty!");
}

static void Main(string[] args)
{
    Console.WriteLine(Eat("apples", "blueberries"));
    Console.WriteLine(Eat("carrots", "daikon"));
}

}