List<?> 的我会 可以用IEnumerable   但是这个Dictionary 搞不定。

解决方案 »

  1.   

    foreach...不过不知道泛型Key和Value的类型你是如何接收的?
      

  2.   


    foreach 怎么搞 不是要有 KeyValuePair<?,?> 这个么 ? 还是要自己设定呀。
    其实也不是不知道类型,就是类型种类太多了。 不能够写死 
      

  3.   


     var a =new Dictionary<string, int>();
                foreach (string c in a.Keys)
                {
                    Console.WriteLine(a[c].ToString());
                }
      

  4.   

    用推断类型var,C# 3.0以上支持...不过不应该这样用...foreach(var item in dic)
    {
    item.Key
    item.Value
    }
      

  5.   

    额可能我说的有点问题。   
    我在设计用SOAP序列化 序列化泛型。(据说已经过时,但是老大让搞定)在修改了soap的序列化格式器 也就是Serialize(Stream stream, object obj) 这个方法。
    这个方法中会反射需要被序列化的对象中的各种字段和属性。因为soap不支持序列化泛型, 所以我将反射出来的泛型List<?>以及Dictionary<?,?> 重新打包进哈希表。
    问题是 fields[i].GetValue(obj) 得到的泛型不能直接使用于是                            Hashtable hst1 = new Hashtable();
                                IEnumerable xValue = fields[i].GetValue(graph) as IEnumerable;
                                int xIndex = 0;
                                foreach (var item in xValue)
                                {
                                    hst1.Add(xIndex, item);
                                    xIndex++;
                                }
    用这种方法来讲List<?> 装进哈希表但是 Dictionary<?,?> 怎么搞