Difference between revisions of "Basic Windows PowerShell 1.0 Types"
(New page: == PowerShell Numeric Types == Windows PowerShell 1.0 supports the full range of .Net number types as outlined in the following table: <table border="1" cellpadding="5" cellspacing="0" i...) |
(No difference)
|
Revision as of 14:48, 18 November 2008
PowerShell Numeric Types
Windows PowerShell 1.0 supports the full range of .Net number types as outlined in the following table:
.Net Type Name |
Short Type Name |
Example |
---|---|---|
System.Int32 |
[int] |
20 |
System.Int64 |
long |
20000000000 |
System.Double |
[double] |
2.1 |
System.Decimal |
[decimal] |
2d |
System.Byte |
[byte] |
2 |
When using a number, it is not usually necessary to prefix the value with the type since PowerShell is generally able to ascertain the correct type based on the size and format of the value. If, for example, the value is too high for an Int32 an Int64 may be created. Similarly, if the number contains a fraction then a Decimal or Double type will be used.
It is possible to identify the type of a variable by using the gettype() method of the object. For example:
PS C:\Users\Administrator> $myval = 10.432 PS C:\Users\Administrator> $myval.gettype() IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Double System.ValueType
As illustrated in the above PowerShell console output, a variable assigned the value 10.432 is stored as type Double by Windows PowerShell.