2014-03-28 36 views
1

晚上好數據,VB.net 2維數組,從列表中

8859-1小時,我在做一個簡單的ASP.net圖網站(DOTNET highcharts.com),我有令人難以置信的麻煩以下內容:

我必須添加一系列圖表與2維數組的對象。所以我不能使用其他任何東西。

這是它的外觀,現在,與硬編碼值:

TokioData = New Object(,) {{1500, 3},{1700, 5}} 

我只需要有從列表/串或任何添加的{值1,值}部分。

但是我無法讓它工作......我真的沒有任何想法,因爲我一整天都在搜索Google,只是想知道如何將KeyValuePairs添加到二維數組中。

回答

1

你可以做到這一點,沒有數組初始化語法。首先,以最小所需尺寸啓動2D陣列。然後使用簡單的For循環將列表中的每個數據添加到2D數組。例如:

'list where data stored initially 
Dim list As New List(Of KeyValuePair(Of Integer, Integer)) _ 
    From 
    { 
     New KeyValuePair(Of Integer, Integer)(1500, 3), 
     New KeyValuePair(Of Integer, Integer)(1700, 5) 
    } 

Dim TokioData As Object(,) 
'initate empty 2D array with size just enough to store all data from list 
TokioData = New Object(list.Count - 1, 1) {} 
'add data from list to 2D array 
For i As Integer = 0 To list.Count-1 
    TokioData(i, 0) = list(i).Key 
    TokioData(i, 1) = list(i).Value 
Next 
+1

你先生,是一個怪異的傳說!謝謝你在那裏。 正是我在找的東西:) – zvaenr

+0

非常歡迎你@zvaenr :) – har07