Wednesday, 2 May 2018

Difference between Call by value and Call by Reference





using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;



namespace ConsoleApplication4

{

    class Program

    {

        public void sum(float a, float b)

        {

           float x=a + b;

           Console.WriteLine(x);

        }



        public int changevalue(int x)

        {

            x = x * x;

            return x;

        }

        public int changereference(ref int x)

        {

            x = x + x;

            return x;

        }

       

        static void Main(string[] args)

        {

            Program p = new Program();

            int a = 5;

            Console.ForegroundColor = System.ConsoleColor.Red;

            Console.WriteLine("call by value ..............................");

            Console.ForegroundColor = System.ConsoleColor.White;

            Console.WriteLine("value from function " + p.changevalue(a));

            Console.WriteLine("actual value of a = "+a);

            Console.ForegroundColor = System.ConsoleColor.Red;

            Console.WriteLine("call by Reference ..............................");

            Console.ForegroundColor = System.ConsoleColor.White;

            Console.WriteLine("output from function : " + p.changereference(ref a));

            Console.WriteLine("actual value of a = " + a);

            Console.ReadLine();

       

        }

    }

}


No comments:

Post a Comment

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...