C# C# Basics Strings Combining Strings

Justin Amyx
Justin Amyx
2,280 Points

How to return multiple types in the same variable

So this code is supposed to return "I think Apples and Blueberries are tasty!".

Program.cs
using System;

class Program
{
    static string Eat(string Firstfood, string Secondfood);
    {
        return (Firstfood + Secondfood;
    }

    // YOUR CODE HERE: Define an Eat method!

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

    }

}
Justin Amyx
Justin Amyx
2,280 Points

While I love learning the coding, I'm finding huge wholes in my ability to understand the classes as they are taught.

I'm confused as to how you use the return function and the above first param, second param that pulls the two parameters from the same code line and puts them into a text string.

3 Answers

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 51,084 Points

You can do this with string concatenation. An example from the teacher's notes for this video:

  static void Main()
    {
        Console.WriteLine("Welcome to the cat food store!");

        string entry = Ask("How many cans are you ordering?");
        Console.WriteLine("You entered " + entry + " cans");
    }

should help you solve it. Treat the parameter names the same way as variable entry in the last line of code.

Justin Amyx
Justin Amyx
2,280 Points

How do you do this with the return function though? I'm not looking for the straight answer to the problem, but I have not understood how most of this works from the beginning of the C# program and am looking for hows and why's so I can understand what I'm doing at this point.

Justin Amyx
Justin Amyx
2,280 Points

Was able to finally figure out where I was misunderstanding the issue.