我有一個UInteger
類型的鍵字典和值是List(Of Session)
其中(公共)類Session
包含幾個變量和一個構造函數(Public Sub New(...))。無法從.NET Dictionary獲取List(Of <my class>)?
一些在我Session
類的變量是:
Private count As Integer
Private StartDate As Date
Private Values As List(Of Integer)
和幾個類似的方法:
Friend Sub Counter(ByVal c as Integer)
count += c
End Sub
沒有問題值添加到字典:
Dim Sessions As New List(Of Session)
Dim dict As New Dictionary(Of Integer, List(Of Sessions))
然後一些代碼來填充會話中的幾個會話對象(這裏沒有顯示)然後:
dict.Add(17, Sessions) ''#No problem
Sessions.Clear()
Sessions = dict(17) ''#This doesn't return anything!
即使代碼沒有返回任何錯誤,Sessions對象也是空的。 我的班課程是否會被存儲在字典中?
不應該是這樣:Dim dict As New Dictionary(Of Integer,List(Of Session))?無論如何,你正在清除剛剛添加到該鍵值的列表,因此在dict(17) – Marc 2010-06-11 13:35:59
@Marc:是的時候它將是空的。這讓我困惑。 – 2010-06-11 13:37:08
對不起,你說得對! :) – Magnus 2010-06-14 08:59:09