如何在 PowerShell 中將字典轉換為雜湊表?


類似於 PowerShell 中的任何其他資料型別轉換,我們可以以類似的方式將字典轉換為雜湊表。 我們有一個名為$CityData的字典示例如下。

Key     Value
---     -----
India      91
Austria    43

其資料型別為字典,

示例

PS C:\> $citydata.GetType() | ft -AutoSize

輸出

IsPublic IsSerial Name         BaseType
-------- -------- ----         --------
True     True     Dictionary`2 System.Object

將其轉換為雜湊表,

$hash = [Hashtable]$citydata

或者

$hash = [System.Collections.Hashtable]$CityData

資料型別

PS C:\> $hash | ft -AutoSize

輸出

Name    Value
----    -----
Austria 43
India   91

更新時間:15-12-2020

974 次瀏覽

開啟你的 職業生涯

完成課程以獲得認證

開始
廣告