0

what is the difference between void and return pls explain in simple words:-)

11th Jul 2016, 8:17 AM
Ankit
Ankit - avatar
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 😁
11th Jul 2016, 8:51 AM
Erwin Mesias
Erwin Mesias - avatar
+ 1
Yeah, No Problem 😁😁 Thanks for the UpVote by the way 😁😁
11th Jul 2016, 8:59 AM
Erwin Mesias
Erwin Mesias - avatar
+ 1
😋
16th Jul 2016, 3:49 PM
Job Getabu
Job Getabu - avatar
0
thank you @erwin
11th Jul 2016, 8:57 AM
Ankit
Ankit - avatar