在给 List<object>集合中添加数据,居然报这个错“集合大小是固定的”用的Add的方法 
语法是:
因为定义的是Dictionary<string,List<object>>给某个键对应的List<object>加数据的时候出的错
aaa.Add(obj);

解决方案 »

  1.   

    如果原来那个List<object>是空的话,加数据没有问题,加第2条就报错了
      

  2.   

    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;
         }
    }
      

  3.   

    没问题,很正确:
    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);
        }
      }
    }
      

  4.   

    这也没问题:
    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);
        }
      }
    }
      

  5.   

    变量定义的问题
    字典中的第2个IList<object>  因为是直接被赋了个值,所以无法再添加数据,这是为什么啊?