C# C# Basics Methods Returning a Value from the Ask Method

Vivian Coday
Vivian Coday
11,868 Points

Further Simplification

Can we simplify the Main method further by removing the variable declaration and instead put the call to the Ask method within the call to Console.WriteLine?

static void Main(string[] args) {
        Console.WriteLine("Welcome to the cat food store!");
        Console.WriteLine(Ask("How many cans are you ordering? "));
    }

1 Answer

Steven Parker
Steven Parker
186,663 Points

You certainly could do that if writing the input back to the output was the only thing the program was going to do.

But it's necessary to store the value in a variable to be able to use it later for other things like computing the order price. You'll see this being done in later examples as the course progresses.