Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net Powershell中的私有作用域和本地作用域有什么区别?_.net_Powershell_Scope_Powershell 2.0 - Fatal编程技术网

.net Powershell中的私有作用域和本地作用域有什么区别?

.net Powershell中的私有作用域和本地作用域有什么区别?,.net,powershell,scope,powershell-2.0,.net,Powershell,Scope,Powershell 2.0,你能解释一下私有范围和本地范围的区别吗 如果我们讲一个例子,如果我创建了一个新的PS驱动器,它的作用域是私有的,那么与使用本地作用域创建它有什么区别 感谢本地变量在子作用域(嵌套脚本块、调用的函数等)中可见。私有变量仅在当前脚本块中可见。一个简单的例子: PS> & { $local:foo = 42; $private:bar = 42; & { "foo is $foo and bar is $bar" } } foo is 42 and bar is 如您所见,$b

你能解释一下私有范围和本地范围的区别吗

如果我们讲一个例子,如果我创建了一个新的PS驱动器,它的作用域是私有的,那么与使用本地作用域创建它有什么区别


感谢

本地变量在子作用域(嵌套脚本块、调用的函数等)中可见。私有变量仅在当前脚本块中可见。一个简单的例子:

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

如您所见,
$bar
对内部脚本块不可见。

本地变量在子范围(嵌套脚本块、调用的函数等)中可见。专用变量仅在当前脚本块中可见。一个简单的例子:

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

如您所见,
$bar
对内部脚本块不可见。

关于
获取有关\u范围的帮助如何?
获取有关\u范围的帮助如何?