2010-07-21 24 views
2

有什麼辦法可以在VB.NET中做同樣的事情嗎?如何在VB.NET中直接填寫字典(TKey,TValue)

Dictionary<int, string> myDict = new Dictionary<int, string>()  
{   
    { 2, "This" },  
    { 1, "is" },   
    { 5, "radio" },  
    { 12, "clash" },  
}; 
+4

同樣的問題http://stackoverflow.com/questions/318530/is-it-possible-to-initialise-a-new-system -collections-generic-dictionary-with-str 檢查jgauffin的回答。下面是一個例子: 'Dim myDic As New Dictionary(Of Integer,String)From {{1,「One」},{2,「Two」}}'。這僅適用於VB.NET 10 – 2010-07-21 14:01:26

回答

8

如上馬塞爾的評論指出:

Dim myDict As New Dictionary(Of Integer, String) From _ 
     {{1, "one"}, {2, "two"}, {3, "three"}} 
這裏
相關問題