假设我有一个类Foo,看起来像这样:
public class Foo : IFoo
{
public Foo()
{
Bars = new List<dynamic>();
}
public IList<dynamic> Bars { get; set; }
}接口IFoo如下所示:
public interface IFoo
{
IList<dynamic> Bars { get; set; }
}现在,当我执行以下操作时:
IFoo foo = new Foo();
dynamic a = new System.Dynamic.ExpandoObject();
a.Prop = 10000;
dynamic b = new System.Dynamic.ExpandoObject();
b.Prop = "Some Text";
foo.Bars.Add(a); // Throws an 'System.Collections.Generic.IList<object>' does not contain a definition for 'Add' - exception!!!!!
foo.Bars.Add(b); // Same here!!!!!我到底做错了什么?
https://stackoverflow.com/questions/15920844
复制相似问题