Method Calls And Input Question

Hello,
Can someone explain what does it mean by saying that "but it doesn’t pass the value 3 to its caller."

Not every method returns a value. Console.WriteLine() , for example, prints 3 to the console but it doesn’t pass the value 3 to its caller. If you’re not sure what a method returns you can always check the Microsoft documentation.

Lesson Link

its explained within the lesson:

When a method returns a value, it essentially passes a piece of data to wherever it was called. One way to capture the returned value of a method is with a variable:

int smallerNumber = Math.Min(3, 4);

the Min method passes the minimum value (3 in this case) to its caller

WriteLine doesn’t pass anything back (return) to its caller. This will become much more clear once you learn the return keyword

int smallerNumber = Math.Min(3, 4);

What is the caller here? Math.Min() or the variable?
Consider, we have the following:

Console.WriteLine(“Lorem ipsum”);

In the code above, we use the method,
Console.WriteLine()
with the argument “Lorem Ipsum”. Does this method return the argument to its caller?

technically, only Min() is the caller. Math is a class. Calling refers to calling methods. So somewhere within the math class is a Min() method.

The variable just captures the returned result.

again explained in the lesson and its what your question started with:

Not every method returns a value. Console.WriteLine() , for example, prints 3 to the console but it doesn’t pass the value 3 to its caller.

same for Lorem Ipsum, its written to the console, but WriteLine doesn’t return anything. This is known as void in C#, the WriteLine method could look something like:

class Console {
   public void WriteLine(){}
}

did you check the documentation mentioned in the lesson?

This topic was automatically closed 18 hours after the last reply. New replies are no longer allowed.