简体   繁体   English

从字符串启动二维数组

[英]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. 我在使用Highcharts.NET时遇到的一个简单的问题要花5个多小时,基本上,我要做的就是用动态数据初始化数组。

I really want to have only this part "{1500,3}" being added from an object, string, list or what ever to the array. 我真的只想从对象,字符串,列表或数组中添加任何部分“ {1500,3}”。

If I'm creating a string with the values "{1500,3}" it tells me of course, that 1 dimension of the array is missing. 如果我要创建一个值为“ {1500,3}”的字符串,那么它会告诉我,当然缺少数组的1维。

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的链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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