简体   繁体   中英

VB.net 2 dimensional array with data from a list

Good evening,

I'm working since 8 hours on a simple ASP.net Chart Website (dotnet highcharts.com) and I'm having incredible trouble with the following:

I have to add a series to a chart with an 2 dimensional array of Object. So I can't use anything else.

This is how it looks right now, with hardcoded values:

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

I only need to have the {value1, value2} part being added from a list / string or whatever.

But I can't get it to work ... I'm really not having any idea, as I'm googling the whole day, just to find out how to add KeyValuePairs to an 2D-Array.

You can do that without array initializer syntax. First, initiate 2D array with minimum required size. Then use simple For loop to add each data from list to 2D array. For example :

'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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM