看System.Windows.Forms.Menu.MenuItemCollection实现了IList等接口。IList中有一个方法是int Add(object value),但是我怎么没有在System.Windows.Forms.Menu.MenuItemCollection中找到这个方法呢? 谢谢

解决方案 »

  1.   

              System.Windows.Forms.Menu.MenuItemCollection m = new Menu.MenuItemCollection();
                m.Add("aaa");
    有啊,为什么说没有,当输入m.之后,Add就提示出来了呀.
      

  2.   

    还是不明白。
     System.Windows.Forms.Menu.MenuItemCollection m = new Menu.MenuItemCollection(); 
     m.Add("aaa");
    这虽然可以,但实现的是Add(string)而不是Add(object)。我试验了一下代码(如下):
        class Base {}
        class Derive : Base {}    interface H
        { void Set(Base b); }    class Imple : H
        {
            public void Set(Derive d) { }
        }
    这根本无法编译,是因为Imple实现的Set中使用的是Base的子类Derive而非Base。那么为什么 System.Windows.Forms.Menu.MenuItemCollection继承自IList而没有实现Add(object),实现了Add(string)就可以了呢?
      

  3.   

    这是显式接口实现,用实例引用是没有的,必须强制转换为IList接口才会有...ps:这问题不是问过了吗...