Monday, April 8, 2019

Difference between call by ref and call by out ?

1) Call by ref should be assigned before using where as Call by Out not required to assign a value.


Key Differences Between Ref and Out in C#

  1. When a variable preceded by the ref keyword is passed to any method then the changes made to it inside the method reflects in its original value. When a variable passed to a method is preceded by out keyword the method returns it without using return keyword.
  2. The ref parameter should be initialized before it is passed to a method. On the other hand, the out parameter must be initialized inside the method it is passed to.
  3. While calling, declaring, or defining a method, ref parameter is explicitly declared as ref. On the other hand, while calling, declaring, or defining a method, out parameter is explicitly declared as out.
 

No comments: