What is Call By Value in C# ?

1 Answers

Rahul Roi
Rahul Roi

Into the C#, the value-type parameters are that pass a copy of the original value to the function rather than reference. That does not modify the original value. The change made in the passed value does not alter the actual value. Into the following example, we have a pass value during the function call.

Example :-
using System;  

namespace CallByValue
    class Program
        // User defined function
        public void Show(int val)
             val *= val; // Manipulating value
            Console.WriteLine("Value inside the show function "+val);
            // No return statement
        // Main function, execution entry point of the program
        static void Main(string[] args)
            int val = 50;
            Program program = new Program(); // Creating Object
            Console.WriteLine("Value before calling the function "+val);
            program.Show(val); // Calling Function by passing value
            Console.WriteLine("Value after calling the function " + val);

Output :-

Value before calling the function 50

Value inside the show function 2500
Value after calling the function 50