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 Methods Method Return Values

I don't understand why Console.WriteLine(question) is necessary when the method already has a name, "ask"

I don't understand why Console.WriteLine(question) is necessary when the method already has a name "ask". We do we have to then use the name question in "Console.WriteLine"?

I just don't understand the purpose of string question when the method can already be called with Ask();

2 Answers

Steven Parker
Steven Parker
210,989 Points

The Ask method outputs a question and then waits for an answer. So, Console.WriteLine is still used when you want to output only.

Also, Console.WriteLine(question) is the way it is used inside the definition of Ask, where calling itself would cause a recursive overflow (an infinite loop).

The Console.WriteLine() is a method created by C# SDK itself;

Or you can see Console.WriteLine() as the method existing in the system which you don't need to write but use/call directly.

While the Ask() is a method that we wrote for this lesson.