While reading an MCSD study guide, I noticed the author said it was illegal to include a return statement in a method that declares the return type void. However, when I created the following method Visual Studio didn't flag it in the editor nor did it fail to compile:
private void ReturnNothing()
{
return;
}
What is the real answer then? Is this legal?
Yes it's definitely legal.
It's only illegal if you try to put a value after the return. This is wrong return 0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With