如何添加多种类型的数据,列出 [英] How to add multiple data types to list
问题描述
我的名单如下,
var serie_line = new { name = series_name , data =new List<float?>() };
在其中包含浮点值,另一份清单,上面的代码数据,我想数据包含了两个不同的数据类型值,字符串和浮点值,当我试图将两个不同的数据类型值如下,
In the above code data in another list which contains float value, I want data to contains two different datatype value that is string and float value, when I am trying to add two different datatype values as follow,
var serie_line = new { name = series_name , data =new List<string, float?>() };
它给了我一个错误
使用泛型类型' System.Collections.Generic.List< T>'需要1个参数
我不能尝试数据=新。清单< Tupple<字符串,浮动>>();
..因为我使用的.NET 3.5 ...任何idea..hw CN我处理这个problem..thank你,
I cannot try for data=new List<Tupple<string,float>>();
..since I am using .NET 3.5...any idea..hw cn I deal with this problem..thank you,
更新---------- ---------问题
----------Updated question---------
输出我需要的是如下,
{
"legend":{"enabled":"true"},
"title":{"text":"Financial"},
"chart":{"type":"pie"},
"series":
[
{"name":"Actual-","data":[["Market Share",20.00],["Sales Growth",30.00],["Operating Profit",40.00],["Actual-Gross Margin %",10.00]]}
]
},
这数据清单应包含一个字符串值和一个浮点值...我想提请饼图中highcharts但输出我得到如下:
this data list should contains one string value and one float value...I want to draw pie chart in highcharts but output I am getting is as follows,
{
"legend":{"enabled":"true"},
"title":{"text":"Financial"},
"chart":{"type":"column"},
"series":[{"name":"Actual","data":[{"Str":"Market Share","Flo":20.00}]},
{"name":"Actual","data":[{"Str":"Sales Growth","Flo":30.00}]},
{"name":"Actual","data":[{"Str":"Operating Profit","Flo":40.00}]},
{"name":"Actual","data":[{"Str":"Gross Margin %","Flo":10.00}]}
]
}
任何想法... ???
Any Idea...???
----------词典使用----------
----------Use of Dictionary----------
var data = new Dictionary<string, float?>();
var serie_line = new { name = series_name, data };
serie_line.data.Add(child_object_name, period_final_value);
但多年平均值给予所需的输出...
只给里面的数据值作为例如,
数据:[市场份额:20.00] ..因为我序列化serie_line成JSON ......但我不想这样way..what我要的是数据:[市场份额,20.00]
but this doesnot give required output... it only gives values inside data as for eg, "data":["market share":20.00].. since I am serializing serie_line into JSON...but I don't want this way..what I want is "data":["market share",20.00]
我希望你得到这个...
I hope u get this...
推荐答案
只需使用
new Dictionary<string, float?>() //if your string value cannot be duplicated
//或
new List<KeyValuePair<string,float?> >
这篇关于如何添加多种类型的数据,列出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!