PS C:> $i = [int] 9.99
PS C:> $i
10
PS C:> $i = 9.99
PS C:> $i
9.99
PS C:> [int] $i = 9.99
PS C:> $i
10
PS C:> $i = 9.99
PS C:> $i
10
How would I take away the type binding from $i without deleting the variable
once I associate a type with it?
- Larry
[double]$i = 9.99
Typing as an integer and then giving it a non-integer value could cause
issues with your logic
--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk
"Larry__Weiss" wrote:
> .
>
- Larry
Try this
$i = 3
$s = "3"
$i | gm
$s | gm
types are assigned implicitly by PowerShell when it recognises the data type.
Even if you do something like
$w = Get-WmiObject win32_networkadapter
$w | gm
you will see that $w has a type
PowerShell can change the type of a variable implicitly or explicitly but
everything will have a type
--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk
"Larry__Weiss" wrote:
> .
>
[int] $i = 10
Thereafter PowerShell will not implicitly change the type association without
explicit direction.
Up until the type was strongly bound to the variable, PowerShell would mutate
the type of the variable as needed.
So, there must be something like a "now-strongly-bound" Boolean like property
associated with a variable.
Consider
PS C:> [int] $i = 1; gi variable:i | fl *
PSPath : Microsoft.PowerShell.Core\Variable::i
PSDrive : Variable
PSProvider : Microsoft.PowerShell.Core\Variable
PSIsContainer : False
Name : i
Description :
Value : 1
Visibility : Public
Module :
ModuleName :
Options : None
Attributes : {System.Management.Automation.ArgumentTypeConverterAttribute}
PS C:> $x = 1; gi variable:x | fl *
PSPath : Microsoft.PowerShell.Core\Variable::x
PSDrive : Variable
PSProvider : Microsoft.PowerShell.Core\Variable
PSIsContainer : False
Name : x
Description :
Value : 1
Visibility : Public
Module :
ModuleName :
Options : None
Attributes : {}
So, that collection bound to the Attributes property makes all the difference
between a variable strongly type bound and one that is not strongly type bound.
So, how does one restore the value of Attributes back to {} ?
I am afraid there is no way to reset it without deleting variable :(
Martin
"Larry__Weiss" <l...@airmail.net> wrote in message
news:eBisaBXa...@TK2MSFTNGP05.phx.gbl...
Looks like that is a "read-only" property from our perspective.
- Larry
Martin
"Larry__Weiss" <l...@airmail.net> wrote in message
news:udz#xPhbKH...@TK2MSFTNGP06.phx.gbl...