static Dictionary<string, IList<object>> list = new Dictionary<string, IList<object>>();foreach (KeyValuePair<string,IList<object>> k in list) { if (k.Key == tablename) { k.Value.Add(value); break; } }
没问题,很正确: using System; using System.Collections.Generic;class Program { static void Main() { Dictionary<string,List<object>> d = new Dictionary<string,List<object>>(); d["a"] = new List<object>(); d["a"].Add(1); d["a"].Add("OK"); d["a"].Add(false); foreach (object o in d["a"]) { Console.WriteLine(o); } } }
这也没问题: using System; using System.Collections.Generic;class Program { static Dictionary<string, IList<object>> list = new Dictionary<string, IList<object>>(); static void Main() { list["a"] = new List<object>(); list["a"].Add(true); list["a"].Add("OK"); foreach (KeyValuePair<string,IList<object>> k in list) { if (k.Key == "a") { k.Value.Add(12345); break; } } foreach (object o in list["a"]) { Console.WriteLine(o); } } }
{
if (k.Key == tablename)
{
k.Value.Add(value);
break;
}
}
using System;
using System.Collections.Generic;class Program
{
static void Main()
{
Dictionary<string,List<object>> d = new Dictionary<string,List<object>>();
d["a"] = new List<object>();
d["a"].Add(1);
d["a"].Add("OK");
d["a"].Add(false);
foreach (object o in d["a"])
{
Console.WriteLine(o);
}
}
}
using System;
using System.Collections.Generic;class Program
{
static Dictionary<string, IList<object>> list = new Dictionary<string, IList<object>>(); static void Main()
{
list["a"] = new List<object>();
list["a"].Add(true);
list["a"].Add("OK");
foreach (KeyValuePair<string,IList<object>> k in list)
{
if (k.Key == "a")
{
k.Value.Add(12345);
break;
}
}
foreach (object o in list["a"])
{
Console.WriteLine(o);
}
}
}
字典中的第2个IList<object> 因为是直接被赋了个值,所以无法再添加数据,这是为什么啊?