0

What does return do? (C#)

Hi, I’m currently learning C# and I can’t for the life of me understand what return does inside a method. Here’s a example: https://code.sololearn.com/cVO10f9iT0B5/?ref=app What happened with the returned value of 3? Did it get printed in the console? Is it stored in a variable somewhere? Please help me understand this.

3rd Jul 2018, 9:58 AM
GustavH
3 ответов
+ 1
"Return" terminates the execution of a function. It can also return a value to the calling code.
3rd Jul 2018, 10:08 AM
josh mizzi
josh mizzi - avatar
+ 1
advice: put methods outside of the main method. also, return is basically a way to return the result of a function, upon returning a value a function is terminated and in your case, nothing happens because you don't store the returned value anywhere. if you were to do "Console.WriteLine(method(...));" then it would output whatever the method returns.
3rd Jul 2018, 11:18 AM
hinanawi
hinanawi - avatar
0
oh okay, so it’s a bit like break but it can also take something away from a function? Thank you both for answering!
3rd Jul 2018, 1:16 PM
GustavH