Techie Talks

Monday, February 14, 2005

Passing by reference in C#

Here is the way to pass values by reference in C#.

Function Declaration
void myFn(int x, ref int y)
{
x = 5;
y = 10;
}

Function call

int i,j;
i = 2; j = 3;
myFn(i, ref j);


Here, i is passed by value to x and j is passed by reference to y.

0 Comments:

Post a Comment

<< Home