While Passing reference to the function any changes made to that variables inside the Function.That will affect the
Main variable value.
—————————————–
When we can Pass it object value as variables it just make a Copy of that variables…… and than it takes to perform
an operation.But while passing the reference Both variables are refer to the same memory location.
using System;
using System.Collections.Generic;
using System.Text;
namespace Java2s
{
enum constants
{
x=1,
a=2,
b=3
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine(constants.a);
Console.WriteLine(constants.b);
Console.WriteLine(constants.x);
Console.WriteLine(int.MaxValue);
Console.ReadLine();
int a = 1;
int b = 2;
Console.WriteLine(“Before Reference a&b is “+a + “ ” +b);
Program Obj = new Program();
Console.WriteLine(Obj.Addition(ref a, ref b));
Console.WriteLine(“After Reference a&b is ” + a + “ ” + b);
Console.ReadLine();
}
public int Addition(ref int a,ref int b)
{
a = 2;
b = 3;
return (a + b);
}
}
}