What is :: ?

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Graham Beer Graham Beer 1 year, 9 months ago.

  • Author
    Posts
  • #23141
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Hi all,

    This is my first post !
    In the line [System.Windows.Forms.MessageBox]::Show("Hello World!") what does the :: mean/do ?
    Also, why is there the need to use "System.Windows.Forms.MessageBox" and not a verb-noun syntax ? What is the difference ?

    Many thanks all !

  • #23142
    Profile photo of Tim Pringle
    Tim Pringle
    Participant

    Hi Graham,

    You are referring to a .NET class, which will often require you to specify it's entire name space as well. The '::' tells PowerShell that what follows is one of the attributes of the class, which typically can consists of one or more constructors, enumerations, methods, or properties.

    Take a look at https://msdn.microsoft.com/en-us/library/system.windows.forms.messagebox%28v=vs.110%29.aspx to get an idea what I'm referring to.

    This is also the reason why there is no Verb-Noun format. You're not referring to a PowerShell cmdlet, but directly to a .NET class.

    If you want to get a list of currently registered cmdlets, you can use the [b]Get-Command[/b] Cmdlet.

    There's some pretty good articles available about using .NET with PowerShell. Take a look at Scripting Guy who has written a few.

    Hope this helps.

  • #23143
    Profile photo of Graham Beer
    Graham Beer
    Participant

    Many thanks

You must be logged in to reply to this topic.