Reference Method
A reference parameter is used for both input and output parameter passing. The argument passed for a reference parameter must be a variable, and during execution of the method, the reference parameter represents the same storage location as the argument variable. A reference parameter is declared with the ref modifier. The following example shows the use of ref parameters.
using System;
class Test
{
static void Swap(ref int x, ref int y) {
int temp = x;
x = y;
y = temp;
}
static void Main() {
int i = 1, j = 2;
Swap(ref i, ref j);
Console.WriteLine("{0} {1}", i, j); // Outputs "2 1"
}
}
Reference: www.dotnetmaterial9.blogspot.com
namespace ref_keyword
{
class keyword
{
static void Main(string[] args)
{
int num = 8;
calcsqure(num);
Console.WriteLine("Value of num without using ref keyword:{0}",num);
refsqure(ref num);
Console.WriteLine("Value of num using ref keyword:{0}",num);
}
static void calcsqure(int inum)
{
inum = inum * inum;
}
static void refsqure(ref int inum)
{
inum = inum * inum;
}
}
}