首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >列表和ICollections

列表和ICollections
EN

Stack Overflow用户
提问于 2010-08-19 06:14:45
回答 5查看 512关注 0票数 0

查看接口System.Collections.Generic.ICollection,它的定义要求继承成员包含属性bool IsReadOnly { get;}

但是,我接着看了类System.Collections.Generic.List,它继承了System.Collections.Generic.ICollection,这个类不包含bool IsReadOnly { get;}的定义。遗传链是怎么断的,还是我漏掉了什么?

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2010-08-19 06:20:11

该成员明确执行:

http://msdn.microsoft.com/en-us/library/bb346454.aspx

票数 1
EN

Stack Overflow用户

发布于 2010-08-19 06:17:05

IsReadOnly属性在那里,但是List<T>正在实现它明确地说

为了让自己相信这一点,你可以:

代码语言:javascript
复制
List<T> genericList = new List<T>();
IList explicitIList = genericList;

bool isReadOnly = explicitIList.IsReadOnly;

这应该是汇编。

您还可能希望查看这个问题和这个文章,了解如何显式实现接口,以及如何从类型外部引用类型上显式实现的成员。

票数 1
EN

Stack Overflow用户

发布于 2010-08-19 06:19:24

它位于IList部分:

IList实现ICollection

代码语言:javascript
复制
    public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable
    {
        public List();
        public List(int capacity);
        public List(IEnumerable<T> collection);
        public int Capacity { get; set; }

        #region IList Members

        int IList.Add(object item);
        bool IList.Contains(object item);
        void ICollection.CopyTo(Array array, int arrayIndex);
        int IList.IndexOf(object item);
        void IList.Insert(int index, object item);
        void IList.Remove(object item);
        bool IList.IsFixedSize { get; }
        bool IList.IsReadOnly { get; }
        bool ICollection.IsSynchronized { get; }
        object ICollection.SyncRoot { get; }
        object IList.this[int index] { get; set; }

        #endregion

...and so on

}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3519184

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档