省略双引号并传递值

本文关键字: | 更新日期: 2023-09-27 18:20:25

在下面的代码中,我有一个字符串数组,它有我想在序列图中传递的值。但我的实际结果是,它以字符串格式传递值,如"1,2,3",但它应该传递值,例如1,2,3。请帮我做这个

string[] Stocks = StockDetails.ToArray();
            string s = string.Join(",", Stocks);
var series = new Collection<Serie>();
  series.Add(new Serie { name = "Current Stock", data = new string[] { s } });

值应类似

 series.Add(new Serie { name = "André", data = new object[] { 4, 15, 5, 17, 14 }, });

省略双引号并传递值

为什么不首先使用Stocks

string[] Stocks = StockDetails.ToArray();
var series = new Collection<Serie>();
series.Add(new Serie { name = "Current Stock", data = Stocks });

为了完整起见,如果您有一个逗号分隔的字符串,如"1,2,3",您可以使用String.Split来获得string[]:

string[] nums = "1,2,3".Split(',');

根据我对你的问题的理解,你有像-这样的数据

 string []Stocks={"1,2,3","2,4,5","3","4"};

因此,您需要按如下方式拆分数据以获得字符串数组-

 string []Stocks={"1,2,3","2,4,5","3","4"};
        string temp_stocks = string.Join(",", Stocks);
        string[] splited_temp_stocks;
        splited_temp_stocks = temp_stocks.Split(',');
        var series = new Collection<Serie>();
        series.Add(new Serie { name = "Current Stock", data = splited_temp_stocks }); 
相关文章:
  • 没有找到相关文章