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 trialJustin Amyx
2,280 PointsHow to return multiple types in the same variable
So this code is supposed to return "I think Apples and Blueberries are tasty!".
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"));
}
}
3 Answers
KRIS NIKOLAISEN
54,972 PointsYou 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
2,280 PointsHow 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
2,280 PointsWas able to finally figure out where I was misunderstanding the issue.
Justin Amyx
2,280 PointsJustin Amyx
2,280 PointsWhile 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.