C Sharp Call By Value

C# Call By Value

Instead of a reference, when a copy of the original value is passed to the function, then it is known as Call by value in C#. The original value is thus neither modified, nor any change in the passed value will alter the actual value.

Example:

using System;  
namespace Func_Example
{  
    class Example  
    {  
        public void Display(int a)  
        {  
             a += a;  
            Console.WriteLine("Value inside the function: "+ a);  
        }  
        static void Main(string[] args)  
        {  
            int a = 100;  
            Example xyz = new Example(); 
            Console.WriteLine("Value before calling: "+ a);  
            xyz.Display(a);            
            Console.WriteLine("Value after calling: " + a);  
        }  
    }  
}

Output:

Explanation:

In the above example, we are passing the value to the function during the function call.

Please Share