Ok,
consider this method
public int sum(int x, int y)
{
int z = x + y;
return z;
}
are the x or y changed during the method process, the response is no for sure, we call those paramters input parameters
Now,
what if you want that x recives the sum of x+y so the x will be at the
same time an input and also an output so it has to be marked as ref
public int sum(ref int x, int y)
{
int x = x + y;
return x;
}
Now, what if the x value is known as input so we dont need to set it, then it will be considered only as an output value
public int sum(out int x, int y)
{
x = 20;
x = x + y;
return x;
}
Interviews3 answers
What is mean by OUT Parameters,Ref Parameters in C#?
3 Answers
Bechir BejaouiPosted Dec 9, 2008, 3:34 PM EST
hi,
Out And Ref are same but the difference is using out parameter we need to assigne the value the variable.
using ref parameter without assgineing the value ref parameter will work
Ravi BSPosted Dec 8, 2008, 6:59 PM EST
Hi,
What is mean by OUT Parameters,Ref Parameters in C#?
Thanks,
Narasima
P NarasimhaPosted Dec 8, 2008, 12:30 AM EST

