C# pointer to the variable
This question already has an answer here:
You are presumably looking for ref
or out
parameters:
private void square(double input, out double output)
{
output = input * input;
}
For ref
or out
parameters, modifications made to the argument are made to the variable that the caller supplied. This is pass-by-reference rather than the default pass-by-value.
Call the function like this:
double d;
square(3.0, out d);
Debug.Assert(d == 9.0);
With an out
parameter the information flows from the function to the caller. A ref
parameter allows data to be passed both into the function as well as out of it.
These language features are documented on MSDN: ref
and out
. And no doubt your text book will cover this subject.
You want to use either ref or out parameter.
private void pierwiastek(ref double c, ref double d)
{
//some code
}
or
private void pierwiastek(out double c, out double d)
{
//some code
}
You have to call the methode with either ref or out keyword:
pierwiastek(ref x, ref y);
or
pierwiastek(out x, out y);
The main difference between these two keywords is that variables that get passed with ref need to be initialized while out doesn't require this. You may want to read the corresponding msdn articles for further information:
ref - http://msdn.microsoft.com/de-de/library/14akc2c7.aspx
out - http://msdn.microsoft.com/de-de/library/t3c3bfhx.aspx
链接地址: http://www.djcxy.com/p/21008.html上一篇: 真的是有价值的传递吗?
下一篇: C#指向变量的指针