Ref and Out Parameter in C# with example

Introduction: Here in this article, I am going explain you about Ref and Out Parameter in C# with example. This article will also explain you about the major differences between Ref and Out Parameter in C#.

Description: Ref and out parameter is used to refer some values and set values.Ref keyword is used to pass by Ref and Out Parameter in C# reference not by value while Out parameters cause a function/method to refer the same variable that is to be passed into the method.

Some useful links

  1. The difference between Machine.Config and Web.config
  2. Create Serial Number in SSRS
  3. Clear dropdown values using JavaScript
  4. Flipkart affiliate API in C#,ASP.NET
  5. Bluehost Discount Coupon: Save up to 63% with Free Domain

Ref and out parameter are useful when we need to return value or values from the method. Ref and out parameter are useful when we need to return value or values from the method.

Ref Parameter:

In ref parameter, we first need to declare the variable in which we pass references. when any charges will be done in the method that will reflect in the variable.

In ref parameter, we should initialize variable otherwise, it will be an error.

Out Parameter:

Out parameter is using to set or return value or values from the method. In out parameter, there is no need to initialized a variable. This type of variable will be initialized by the method itself.

Feedback: If this Article is helpful to you, Please comment your feedback in below comment section

Anand Kumar
@anandkumarv

Anand Kumar

Sr.Tech Lead at CsharpMagic
I am founder of csharpmagic.com and by profession Sr.Tech Lead. I like to explore New Technologies, New Business idea and many more
Anand Kumar
@anandkumarv

Latest posts by Anand Kumar (see all)

Anand Kumar

I am founder of csharpmagic.com and by profession Sr.Tech Lead. I like to explore New Technologies, New Business idea and many more

Leave a Reply

Your email address will not be published. Required fields are marked *