I've tried this code in PowerShell ISE and VS Code with the same strange result. Without a breakpoint, the output is EMPTY
, but with a breakpoint in the line with "NULL"
, the output is NULL
(as expected). Why?
function demo {
param(
[string] $value = [NullString]::Value
)
if ($null -eq $value) {
"NULL"
} elseif ($value -eq '') {
"EMPTY"
} else {
"$value"
}
}
demo
I know now, that PowerShell will always convert a non-string value (e.g. $null or [NullString]::Value) to an (empty) string, when you use the type modifier [string] for a parameter. Fine, I can live with that, but it's hard to figure that out by yourself, if debugging is so weird in this case.