C# Program for Pass by Value

This article shows the use of pass by value in C#. You may go through the following theory on pass by value in C#, click the link below.

The program has a variable num value which is passed to the method square() as an argument. This calculates and displays the results in it.


C# Program to implement Pass by Value

Source code: C# program to implement call by value

using System;

class passByValue
{
  static void square(int a)
  {
    a = a * a;
    Console.WriteLine("Value Within the Cube method : {0}", a);
  }

  static void Main()
  {
    int num = 10;
    Console.WriteLine("Value of num before the Method is called : {0}", num);

    // passing the value of num 
    square(num);

    Console.WriteLine("Value of num after the Method is called : {0}", num);
    Console.ReadKey();
  }
}

Output: