powershell - "::"有什么作用?如何在 powershell 脚本中使用 "::"?

标签 powershell variables operators

它是否等同于 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/

相关文章:

powershell - 让标准输入进入 Powershell 流

powershell - 保存凭据以供 powershell 重用和错误 ConvertTo-SecureString : Key not valid for use in specified state

C结构初始化变量

c++ - 使用运算符 << 的日志记录功能

c++ - 如何在流缓冲区C中添加参数

eclipse - 从 Eclipse IDE 启动 PowerShell 脚本

powershell - 什么是@”运算符?

variables - 带变量的 Excel VBA 公式

javascript - 不带 eval 的字符串到变量名

c - 为什么代码 "x++ && y++;"在没有控制运算符的情况下可以在 C 中运行?