0
what is the difference between void and return pls explain in simple words:-)
4 Answers
+ 9
void method:
it does not return a value.
returning method is the opposite, it does return a value.
for example.
you have:
static void VoidPrint()
{
string word = "hello";
}
//VoidPrint() does not carry any value. What it only did is that it put the word "hello" inside the local variable 'word' and that's it.
while
static string ReturningPrint()
{
string word = "hello";
return word;
}
//ReturningPrint() now holds the value "hello"
in your Main method,
if you put:
Console.WriteLine(ReturningPrint());
//it will print hello.
while,
if you put:
Console.WriteLine(VoidPrint());
//it will cause an error because it is void and it does not hold any value.
â void method does ânot save or return values in itself.
It just performs what it has to perform and that's it.
â while returning method, it â saves or returns value in itself, so when you call it, it carries a value; the value you returned.
Hope that helps đ
+ 1
Yeah, No Problem đđ
Thanks for the UpVote by the way đđ
+ 1
đ
0
thank you @erwin