Why ref and out are treated identical at compile time

Posted by Gsm_Gsv under ASP.NET on 6/9/2014 | Points: 10 | Views : 1074 | Status : [Member] | Replies : 1
Private void displayNo(int a )
Private void displayNo( ref int a)
Private void dispalyNo( out int a)

The above bit of code will result in error "Cannot define overloaded method 'displayNo' because it differs from another method only on ref and out."

Why ref and out together cannot be overloaded??

Can anyone tell in simple words???

Live the life you've dreamed



Posted by: kgovindarao523-21772 on: 6/10/2014 [Member] [MVP] Bronze | Points: 25


1. The ref and out keywords cause different run-time behavior
2. They are not considered part of the method signature at compile time.
3. So, methods cannot be overloaded if the only difference is that one method takes a ref argument and the other takes an out argument.

Thank you,

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

Login to post response