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.
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.
Difference between Ref and Out keywords
|ref keyword||out 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.
- C# | Keywords
- Difference between var and dynamic in C#
- Difference between Hashtable and Dictionary in C#
- Difference between Class and Structure in C#
- Difference between SortedList and SortedDictionary in C#
- Difference between Boxing and Unboxing in C#
- Difference between Managed and Unmanaged code in .NET
- Difference between Abstract Class and Interface in C#
- Difference between readonly and const keyword in C#
- Difference between Method Overriding and Method Hiding in C#
- Difference between System Level Exception and Application Level Exception in C#
- C# | Difference between Static Constructors and Non-Static Constructors
- How to set the Size of the FlowLayoutPanel in C#?
- How to set the Auto Size Mode of FlowLayoutPanel in C#?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.