您能解释一下 Private 和 Local 范围之间的区别吗?
如果我们举个例子,如果 II 创建一个具有私有范围的新 PS 驱动器,与使用本地范围创建它相比有什么区别?
谢谢
您能解释一下 Private 和 Local 范围之间的区别吗?
如果我们举个例子,如果 II 创建一个具有私有范围的新 PS 驱动器,与使用本地范围创建它相比有什么区别?
谢谢
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.