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 (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.