0
what is the difference between void and return pls explain in simple words:-)
4 Antworten
+ 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