Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# C# Basics (Retired) Console I/O Formatting Output

david handy
david handy
308 Points

Parameters

I'm having a hard time understanding the parameters. Can I get a little more clarification on this topic? thanks

CodeChallenge.cs
string entry = ("firstName");
    Console.ReadLine(string , Console.WriteLine);

1 Answer

Jon Wood
Jon Wood
9,884 Points

The first part of the challenge just wants you to call Console.ReadLine() and assign what you input from the console into a string variable called firstName.

The second part of the challenge wants you to use Console.WriteLine() to write what's in the variable firstName into the output window.

Parameters are extra information a method needs in order to do its work. Mainly parameters are used to generalize a method so it can be used in multiple places. Console.WriteLine() is a weird example, since it has almost 20 overloads (methods of the same name, but it takes in different parameters or types of parameters (string, int, etc.)).

For another example, let's take an add method:

public int Add(int x, int y)
{
  return x + y;
}

For our add method to work we need to pass in the information to work on, in this case two integers to add. The names of those parameters we define in the method signature - public int Add(int x, int y) and we can use those names within the body of our method - return x + y;. Outside of the method, though, we can't access those names again.

Hope that somewhat helps, but I'll be glad to explain more.