我已经读过.NET支持返回引用,但C#没有.有特殊原因吗?为什么我不能做这样的事情:
static ref int Max(ref int x, ref int y)
{
if (x > y)
return ref x;
else
return ref y;
}
Run Code Online (Sandbox Code Playgroud) 我可以返回对double值的引用吗?
这就是我想要做的:
ref double GetElement()
{
......
// Calculate x,y,z
return ref doubleArray[x,y,z];
}
Run Code Online (Sandbox Code Playgroud)
要像这样使用它
void func()
{
GetElement()=5.0;
}
Run Code Online (Sandbox Code Playgroud)
这就像在C++中返回一个双指针......我知道我写它的方式是错误的......但是有没有正确的方法呢?