它是否等同于C#中的objectName.method或属性?一个示例或2将有助于准确学习如何使用::
的语法答案 0 :(得分:8)
来自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