我不確定在字典聲明中訪問類的屬性所需的語法。VB.NET訪問字典中的類變量
Public food As New Dictionary(Of String, cheese) From
{
{"cheese1", New cheese},
{"cheese2", New cheese},
{"cheese3", New cheese}
}
Public Class cheese
Public info As New Dictionary(Of String, Array) From
{
{"attributes1",
{New Dictionary(Of String, String) From
{
{"name", "test"},
{"taste", vbNullString},
{"color", vbNullString}
}
}
},
{"attributes2",
{New Dictionary(Of String, String) From
{
{"name", "test"},
{"taste", vbNullString},
{"color", vbNullString}
}
}
}
}
End Class
所以,如果我想測試和使用MsgBox()
我怎麼涓滴在food > cheese1 > info > attributes2 > name
拉,說,name
?
編輯: 我剛剛意識到Array
在info
需要是詞典的關聯數組,所以請忽略錯誤,只是假設它是一個詞典這個問題的緣故。
這有一些非常糟糕的代碼氣味。你不會在任何地方訪問類屬性(屬性),只是字典鍵和值。這是你的意圖嗎? – 2012-03-26 15:19:06