out 关键字如何确定在传递之前未声明的变量的范围?

how does the out keyword determine scope for a variable that was not declared before being passed?

当我调用一个带有 out 参数的函数并且在调用它之前没有声明用作参数的变量时,新变量的范围是什么?

我注意到我可以做到这一点:

if (functionTakesOut(out int newInteger)) {
  Console.WriteLine(newInteger);
}
Console.WriteLine(newInteger);

和两个 Console.WriteLine() 调用都将起作用。

在示例中,您使用的范围将是 local...因为您将其声明为 通过。

本质上是一样的:

int newInteger;
if (functionTakesOut(out newInteger)) 
{
  Console.WriteLine(newInteger);
}
Console.WriteLine(newInteger);