在c#中连接列表的元素

时间:2014-09-12 20:28:56

标签: c#

我想在C#中尝试一些使用集合和泛型的例子,但我仍然坚持这个例子。

这是我在c#,

中的代码
public List<string> CurrentCount(int week, int year)
{
      List<string> lst = new List<string>();
      lst.Add("current:");
      lst.Add("10");
      lst.Add("target:");
      lst.Add("15");

   return lst;
}

It gives me result like this : 
["current:","10","target:","15"]

But I want it like this : 
["current": 10,"target": 15] or
["current": "10","target": "15"]

任何想法都会有所帮助。

感谢。

1 个答案:

答案 0 :(得分:1)

您需要Dictionary,而不是List

var dict = new Dictionary<string, int>();
dict.Add("current", 10);
dict.Add("target", 15);
相关问题