In this article we will explain What is Output parameter in C sharp? Or what is the advantage of out parameter? Or How to use out parameter in C# programming? Or Why use out parameter in C#? With example.



C# out parameter is such type of parameter that is declared with out keyword. It is the same as reference parameter, that doesn’t create memory allocation.

Why use out parameter in C#?

In C# a return statement can be used for returning only one value from a function. Sometime, you required to return multiple values from a single method. In this situation, you need such type of function that can produce multiple output result from a single function. The output parameter C# lets your program to return multiple values.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace out_parameter
   class Program
            //Accept two input parameter and returns one out value
       public static void calculateAmount(int Rate, int amount,
       int discountpercent, out int  totalamount, out int discount)
                totalamount = Rate * amount;
                discount = totalamount *discountpercent / 100;
                totalamount = totalamount -discount;
            static void Main(string[] args)
                int totalamount;
                 int totaldiscount;
                //passing two parameter and getting one returning value
                Program.calculateAmount(1, 4000,5, out totalamount, out totaldiscount);
                Console.WriteLine("Total Paid Amount: {0}\t", totalamount);
                Console.WriteLine("TotalDiscount Amount : {0}\t", totaldiscount);
        }  }


C# Out Parameter with Example

I hope this article will help to you.

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like