PowerShell 范围
示例
变量的默认范围是封闭容器。如果在脚本或其他容器之外,则范围为Global。要指定作用域,应在变量名之前添加前缀,$scope:varname如下所示:
$foo = "Global Scope"function myFunc {
$foo = "Function (local) scope"
Write-Host $global:foo
Write-Host $local:foo
Write-Host $foo
}
myFunc
Write-Host $local:foo
Write-Host $foo
输出:
Global ScopeFunction (local) scope
Function (local) scope
Global Scope
Global Scope
以上是 PowerShell 范围 的全部内容, 来源链接: utcz.com/z/315837.html