automation-null

Why and how are these two $null values different?

蓝咒 提交于 2019-12-17 07:48:19
问题 Apparently, in PowerShell (ver. 3) not all $null 's are the same: >function emptyArray() { @() } >$l_t = @() ; $l_t.Count 0 >$l_t1 = @(); $l_t1 -eq $null; $l_t1.count; $l_t1.gettype() 0 IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Object[] System.Array >$l_t += $l_t1; $l_t.Count 0 >$l_t += emptyArray; $l_t.Count 0 >$l_t2 = emptyArray; $l_t2 -eq $null; $l_t2.Count; $l_t2.gettype() True 0 You cannot call a method on a null-valued expression. At line:1 char:38 + $l

Why and how are these two $null values different?

别等时光非礼了梦想. 提交于 2019-11-26 23:11:36
Apparently, in PowerShell (ver. 3) not all $null 's are the same: >function emptyArray() { @() } >$l_t = @() ; $l_t.Count 0 >$l_t1 = @(); $l_t1 -eq $null; $l_t1.count; $l_t1.gettype() 0 IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Object[] System.Array >$l_t += $l_t1; $l_t.Count 0 >$l_t += emptyArray; $l_t.Count 0 >$l_t2 = emptyArray; $l_t2 -eq $null; $l_t2.Count; $l_t2.gettype() True 0 You cannot call a method on a null-valued expression. At line:1 char:38 + $l_t2 = emptyArray; $l_t2 -eq $null; $l_t2.Count; $l_t2.gettype() + ~~~~~~~~~~~~~~~ + CategoryInfo :