简体   繁体   中英

Initiate two dimensional array from string

I'm working more than 5 hours on a freaking simple problem I have using Highcharts.NET Basically all I want to do, is to initiate an array with dynamic data.

I really want to have only this part "{1500,3}" being added from an object, string, list or what ever to the array.

If I'm creating a string with the values "{1500,3}" it tells me of course, that 1 dimension of the array is missing.

This is the part, I need to have dynamically with values from a list / string etc.

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

I would recommend using a list over an array, especially if you want to add / remove values later in your code:

    Dim TokioData As New List(Of KeyValuePair(Of Integer, Integer))
    TokioData.Add(New KeyValuePair(Of Integer, Integer)(1500, 3))
    TokioData.Add(New KeyValuePair(Of Integer, Integer)(1700, 5))
    TokioData.Add(New KeyValuePair(Of Integer, Integer)(1800, 13))

One of the great thing about lists are that you don't have to re-declare the size when adding values like you do with an array. There is also built in functionality if you need to convert that list to an array:

    TokioData.ToArray()

在c#中,您可以使用dynamic关键字,但不确定在VB中是否存在此关键字,但是这里是有关dynamics的链接

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