C# Function call by value

When you call the function by value, the copy of the actual value is passed in the function instead of its reference. The following example includes the function call by value.

using System;                                                        
public class Program
{
            public int square (int m)
            {
                        return m*m;
            }
            public static void Main(string[] args)
            {
                        int num=Convert.ToInt32(Console.ReadLine());
                        Program p1=new Program();
                        int m=p1.square(num);
                        Console.WriteLine(m);                    
            }
}
Output
10
10 X 10 is 100



ADVERTISEMENT
ADVERTISEMENT