Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Short description
Describes the type accelerators available for .NET types.
Long description
Type accelerators are aliases for .NET types. They allow you to access specific
.NET types without explicitly using the full type name. For example, you can
shorten [System.Management.Automation.AliasAttribute]
to [Alias]
.
Type accelerator names are mostly lowercase, but some are defined using Pascal-case. PowerShell is case-insensitive, so you can use either.
Using type accelerators
For most type accelerators, you use type accelerators in the same way as you would use the full type name. However, PowerShell has special handling for the following two type accelerators:
pscustomobject
- See about_PSCustomObjectref
- See about_Ref
Type accelerators are most commonly used to specify the type of a variable or
cast an object to a specific type. For those cases, you must enclose the type
name or its accelerator in square brackets ([]
). For example, [int]
or
[int32]
.
In some contexts, you can specify the type accelerator name as a string. For example:
When used with type comparison operators
PS> '1' -as 'int' 1 PS> 1 -is 'int' True
When used with
[type]
type classPS> [type]'int' IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Int32 System.ValueType
In other contexts, like reflection, you must use the full type name as a string rather than the type accelerator name.