.net - Powershell 中的私有(private)范围和本地范围有什么区别?

标签 .net powershell scope powershell-2.0

您能解释一下私有(private)范围和本地范围之间的区别吗?

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

谢谢

最佳答案

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

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

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

关于.net - Powershell 中的私有(private)范围和本地范围有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17025818/

相关文章:

windows - Powershell 配色方案?

c# - 使用 C# 中的 Invoke-SqlCmd cmdlet 执行 PowerShell 脚本

c# - .NET https身份验证(Pingdom API)

powershell - 无法从函数内部修改脚本范围的变量

c - 在 C 中,如何使常量仅对特定源文件可见?

.net:如何在 C# 中执行带有可为空参数的存储过程?

.net - 在 .NET 核心中实现 RSA

c# - 如何显示构建版本以及它在我的程序中是在 64 位还是 32 位上运行?

.net - 当应用程序部署在 Azure Web App 中时,无法使用 HiqPDF 生成 PDF

javascript - 使用命名空间将原型(prototype)对象分配给对象中的匿名函数,这是未定义的?