Return the value when returntype is void

Posted by Mahesh_Chs under Interview Questions on 1/25/2013 | Points: 10 | Views : 974 | Status : [Member] | Replies : 4
hii

Is there any chance to return the value, when the return type is void. If yes how ?


Thanks & Regards
Mahesh Chayanam




Responses

Posted by: Ankur56600 on: 1/26/2013 [Member] Starter | Points: 25

Up
0
Down
no there is no chance to return a value when return type is void because void keyword tells the compiler that the function should not return any value ...

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sheonarayan on: 1/26/2013 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
You may pass an output parameter to the method and set the value inside the method and use it. More on output parameter here http://www.dotnetfunda.com/articles/article1526-csharp-out-parameter-explored.aspx

Alternatively, you can use the parameter by ref, see the thread here that discuss about it http://www.dotnetfunda.com/forums/thread3303-difference-between-ref-and-out-parameters-in-csharp.aspx.

Hope this helps.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Toabhishek13 on: 1/31/2013 [Member] Starter | Points: 25

Up
0
Down
Not possible as code will not compile.

Thanks
Abhishek

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kundan64 on: 1/31/2013 [Member] Starter | Points: 25

Up
0
Down
You can use Parameter in the 'void' method as 'ref' and 'out', it will return the value in the Parameter, but void method can not return any value.

Mahesh_Chs, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response