VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/difference-between-ref-and-out-keywords-in-c-sharp/

⇱ Difference between Ref and Out keywords in C# - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Difference between Ref and Out keywords in C#

Last Updated : 11 Jul, 2025

The out is a keyword in C# which is used for the passing the arguments to methods as a reference type. It is generally used when a method returns multiple values. The out parameter does not pass the property.

Example :

Output:

The sum of the value is: 160

The ref is a keyword in C# which is used for the passing the arguments by a reference. Or we can say that if any changes made in this argument in the method will reflect in that variable when the control return to the calling method. The ref parameter does not pass the property.

Example:

Output:

Hello!!Geek
GeeksforGeeks
Difference between Ref and Out keywords
ref keywordout keyword
It is necessary the parameters should initialize before it pass to ref. It is not necessary to initialize parameters before it pass to out.
It is not necessary to initialize the value of a parameter before returning to the calling method.It is necessary to initialize the value of a parameter before returning to the calling method.
The passing of value through ref parameter is useful when the called method also need to change the value of passed parameter.The declaring of parameter through out parameter is useful when a method return multiple values.
When ref keyword is used the data may pass in bi-directional. When out keyword is used the data only passed in unidirectional.

Note:

Both

ref

and

out

parameter treated same at compile-time but different at run-time.

Comment
Article Tags:
Article Tags:

Explore