我在Powershell中有一個用字典填充列表的函數。當填充arrayList時,Powershell會添加整數
Function Process-XML-Audit-File-To-Controls-List($nodelist){
#Keep an array list to track the different controls
$control_list = New-Object System.Collections.ArrayList
foreach($var in $nodelist)
{
$lines = [string]($var.InnerText) -split '[\r\n]'
$control_dict = @{}
foreach($line in $lines){
$line_split = $line.Trim() -split ':',2
if($line_split.Length -eq 2){
$control_dict.Add($line_split[0],$line_split[1])
}
}
$control_list.Add($control_dict)
}
return $control_list
}
不是接收僅返回哈希表,它返回它具有的Int32和Hashtable,那裏是一個Int32在它的每個哈希表元素的列表中的ArrayList:
True True Int32 System.ValueType
True True Int32 System.ValueType
True True Int32 System.ValueType
True True Hashtable System.Object
True True Hashtable System.Object
True True Hashtable System.Object
我不是真的確定爲什麼我的ArrayList中有這些整數。
除$ control_dict是散列表類型?剛剛嘗試過你的方法,它仍然產生相同的結果 –