2

您能解释一下 Private 和 Local 范围之间的区别吗?

如果我们举个例子,如果 II 创建一个具有私有范围的新 PS 驱动器,与使用本地范围创建它相比有什么区别?

谢谢

4

1 回答 1

4

Local vars are visible in child scopes (nested script blocks, functions called etc.) Private vars are only visible in the current script block. A simple example:

PS> & { $local:foo = 42; $private:bar = 42; & { "foo is $foo and bar is $bar" } }
foo is 42 and bar is

As you can see, $bar is not visible to the inner script block.

于 2013-06-10T17:07:12.573 回答