C# C# Basics Strings Combining Strings

Blue DiamondXD
Blue DiamondXD
4,504 Points

Define an Eat method that takes two string parameters. Eat should return a string in the form "I think [first parameter]

i dong get it

Program.cs
using System;

class Program
{

    // YOUR CODE HERE: Define an Eat method!
    static void Eat(string have)
    {

    }

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

}

2 Answers

Steven Parker
Steven Parker
176,675 Points

The instructions say "Define an Eat method that takes two string parameters", but this method takes only one parameter ("have").

They also say "Eat should return a string ...", but this method is not returning anything (it's declared as "void").

Then, the job is to build a string by combining the arguments with other words, which can be done various ways including by interpolation with a template, or more simply by concatenation.

Finally, "return" the constructed string.

Tammi Thomas
Tammi Thomas
4,379 Points
using System;

class Program
{
    static string Eat(string first, string second)
    {
       Console.Write($"I think {first} and {second} are tasty!");
        return Console.ReadLine();
    }

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