如何在Powershell中检查关联数组是否为空 [英] How to check if an associative array is empty in powershell

查看:284
本文介绍了如何在Powershell中检查关联数组是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$a = @() 

如何检查上面的$a是否为空(是).我想得到$true作为答案.

How do I check if $a above is empty (which it is). I would like to get $true as answer.

推荐答案

这不是一个关联数组,它是一个常规数组,但是答案是相同的.使用.Count并与0比较.

That's not an associative array, it's a regular array, but the answer is the same. Use .Count and compare to 0.

关联数组在PowerShell中称为[hashtable],其字面形式使用@{}(花括号).

An associative array is called a [hashtable] in PowerShell and its literal form uses @{} (curly braces).

@{}.Count -eq 0  # hashtable (associative array)
@().Count -eq 0  # array

这篇关于如何在Powershell中检查关联数组是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆