Here we discus ref and out parameters in c#. We can use these
parameters in different ways.
Ref Parameter:-
It is used as a call by reference value in c#. When its
value of parameter is changed in the method, it gets reflected in the calling
method.
Out parameter:-
It is used like a ref parameter, but argument can be passed
without any value assigning to it. Sometime we do not want to give an initial
value to parameter; in this case we use out keyword. The declaration of out
keyword is same as ref keyword.
Important facts about ref and out keywords:-
We cannot use ref and out keyword in method overloading
simultaneously. Ref and out keyword treated as same datatype at compile time
but differently at run-time. Hence method with single parameter cannot be
overloaded when one method take ref parameter and another method take out
parameter.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.