我希望将一些变量传递给函数并将它们设置为其他东西,而不是从它们读取.我打算在我可以创建对象的场景中使用它,并将其添加到执行队列中.指针是否适合这个?
我知道我的问题解释不好,但我不知道更好的解释方法.
public static void SetVariables(out int x, ref int y)
{
// Can't *read* from x at all before it's set
x = 10;
// Can read and write y
y++;
}
public static void Foo()
{
int setOnly;
int increment = 5;
SetVariables(out setOnly, ref increment);
Console.WriteLine("{0} {1}", setOnly, increment); // 10 6
}
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅我的参数传递文章
| 归档时间: |
|
| 查看次数: |
104 次 |
| 最近记录: |