我在下面编写了一个代码,其中我将ArrayList对象分配为字典Items.But当我运行时,Sort方法没有任何反应。我在下面做了什么错误?
Set Dic = CreateObject("Scripting.Dictionary")
Set ArrListChildDetails = CreateObject("System.Collections.ArrayList")
For Row=3 to ob1.Range.Rows.Couny
For I=2 to ob1.Range.Columns.Count
ArrListChildDetails.Add(ob.Cells(Row,I))
Next
Dic(ob.Cells(Row,1))=ArrListChildDetails
Next
For Each D in Dic.Keys
Dic(d).Sort() 'It is not working whereas Dic items are ArrayList object
Next
谢谢,
答案 0 :(得分:1)
根据我的评论,如果您真的希望对项目进行排序,则需要进行两级排序。目前还不清楚您需要排序的是什么或哪个级别。
ArrayList
尝试:
For Row=3 to ob1.Range.Rows.Couny
Set ArrListChildDetails = CreateObject("System.Collections.ArrayList")
For I=2 to ob1.Range.Columns.Count
ArrListChildDetails.Add(ob.Cells(Row,I))
Next
arrListChildDetails.Sort()
Dic(ob.Cells(Row,1))=ArrListChildDetails
'-- didn't use .Clear() so data & old Capacity will get wiped off as well
Set arrListChildDetails = Nothing
2.要对字典级别进行排序,请使用您自己的sort()函数在dictionary
内进行排序:
Dic(d).SortUserBuilt()
注意:强>
AND 每个ARRAYLIST不是一个字典,如果是这样,为什么MSDN会创建两种不同的对象类型?... reference。和Array/list vs Dictionary (why we have them at first place)?