Function Parameter In C#

Parameter is the importaint part of function. However, it is optional but it makes C# function more dynamic than simple and easy function. There are two type offunction parameter in C#, Value type parameter and reference type parameter, that is discussed in lateral chapter in this section.

C# parameter  just a way to passing value to the function and then function calculate the value and then returns appropriate results. You can understand C# function parameter clearly in the following example.

Example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Understanding_Parameter_Example
{
    class Program
    {
        // function with parameter
        public static int Power(int n1)
        {
            int result;
            result = n * n;
            return result;
        }
        static void Main(string[] args)
        {
            int pow;
            // passing arguement as parameter
            pow = Program.Power(5);
            Console.Write("\nPower = {0}", pow);
            Console.ReadLine();
        }
    }
}

Leave a Reply

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