简体   繁体   中英

What does “ :: ” do and how do you use “ :: ” in powershell scripts?

Is it the equivalent of objectName.method or attribute in C#? An example or 2 would be helpful to learn exactly how to use this syntax of ::

From the about_Operators help topic:

 :: 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 

That's basically it.

The static member operator takes a type literal on the left hand side, and allows access to that type's static members (methods and properties alike):

# The PowerShell class can only be instantiated through a static method called Create()
$psInstance = [powershell]::Create()

You can also use it on a variable containing a type:

$dt = [datetime]
$UtcTimestamp = $dt::UtcNow

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM