Converting from C # to Powershell Syntax

In C #, I can use a method Console.Error.WriteLine. This does not work in Powershell, instead I have to write

[Console]::Error.WriteLine

Why square brackets, why double colons?

ps. To be clear, I am not interested in registering; I want to understand the syntax about types and objects and methods.

+3
source share
3 answers

Brackets = Type Access

double colons = access to a static member of the type: [MyType] returns an instance of the type

Example:

c:> [System.Int32]

IsPublic IsSerial Name BaseType

-------- -------- ---- --------

True True Int32 System.ValueType

using dotted notation, you will only get access to the members of the instance of the type instance (for most, reflection methods are applied) ...

c:\> [System.Int32].Parse("3")

Method call failed because [System.Runtype] does not have any "Parse" member

c:\> [System.Int32].AssemblyQualifiedName

System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

so::

c:\> [System.Int32]::Parse("3")
3
+10

[] - Powershell . :: , . .

, .NET. # . , ++ :: , .

+5

All Articles