相关疑难解决方法(0)

Count属性如何在Powershell中运行?

我做了一个非常不幸的错字,花了我相当宝贵的时间:

$errors.Count
Run Code Online (Sandbox Code Playgroud)

0即使存在错误,也会返回" ",因为变量名称应该是单数.这确实有效:

$error.clear()                # To ensure a correct repro
Copy-Item asdf fdsa           # Will show an error
$error.Count                  # Will output "1"
Run Code Online (Sandbox Code Playgroud)

但是,我现在想知道为什么$errors.Count给了我任何东西,为什么它给了我" 0".所以我继续做了一些测试,得到了以下结果:

$asdf.Count                   # Will output "0"
$nrOfEinsteinsInSpace.Count   # Will output "0"
$a = 0; $a.Count;             # Will output "1"
$b = 2; $a.Count;             # Will output "1"
$x = 1,2,3; $x.Count;         # Will output "3"
Run Code Online (Sandbox Code Playgroud)

并且收集更多数据以便能够在这里提出一个明智的问题:

$true.Count                   # Will output "1"
$false.Count                  # Will output …
Run Code Online (Sandbox Code Playgroud)

powershell

13
推荐指数
2
解决办法
5010
查看次数

标签 统计

powershell ×1