PowerShell 中 Dictionary 和 HashTable 有什么区别?
虽然 Dictionary 有一些优点,但 PowerShell 程序员通常更喜欢 Hashtable。请参见以下区别。
a. 与 Hashtable 相比,Hashtable 易于声明,而 Dictionary 稍微复杂一些。例如,
要创建一个哈希表,
$hash = @{
'Country' = 'India'
'Code' = '91'
}要创建字典,
$citydata = New-Object System.Collections.Generic.Dictionary"[String,Int]"
$citydata.Add('India',91) b. Hashtable 位于名为 Collections 的命名空间中,而 Dictionary 位于名为 System.Collections.Generic 的命名空间中。Hashtable 是非泛型的,因此可以是不同数据类型的集合,而 Dictionary 属于泛型类,因此是特定数据类型的集合。
c. Hashtable 和 Dictionary 的 BaseType 均为 Object,但其数据类型不同。Hashtable 有一个“Hashtable”数据类型,Dictionary 有 Dictionary`2 数据类型。
Hashtable
IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Hashtable System.Object
Dictionary
IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Dictionary`2 System.Object
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP