它是否等同于 C# 中的 objectName.method 或属性?一个或两个示例将有助于准确了解如何使用::的这种语法
最佳答案
来自 about_Operators 帮助主题:
:: Static member operator Calls the static properties operator and methods of a .NET Framework class. To find the static properties and methods of an object, use the Static parameter of the Get-Member cmdlet. [datetime]::now
基本上就是这样。
静态成员运算符在左侧接受一个类型文字,并允许访问该类型的静态成员(方法和属性等):
# The PowerShell class can only be instantiated through a static method called Create()
$psInstance = [powershell]::Create()
您还可以在包含类型的变量上使用它:
$dt = [datetime]
$UtcTimestamp = $dt::UtcNow
关于powershell - "::"有什么作用?如何在 powershell 脚本中使用 "::"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38483692/