查看接口System.Collections.Generic.ICollection,它的定义要求继承成员包含属性bool IsReadOnly { get;}。
但是,我接着看了类System.Collections.Generic.List,它继承了System.Collections.Generic.ICollection,这个类不包含bool IsReadOnly { get;}的定义。遗传链是怎么断的,还是我漏掉了什么?
发布于 2010-08-19 06:20:11
该成员明确执行:
http://msdn.microsoft.com/en-us/library/bb346454.aspx
发布于 2010-08-19 06:17:05
IsReadOnly属性在那里,但是List<T>正在实现它明确地说。
为了让自己相信这一点,你可以:
List<T> genericList = new List<T>();
IList explicitIList = genericList;
bool isReadOnly = explicitIList.IsReadOnly;这应该是汇编。
您还可能希望查看这个问题和这个文章,了解如何显式实现接口,以及如何从类型外部引用类型上显式实现的成员。
发布于 2010-08-19 06:19:24
它位于IList部分:
IList实现ICollection
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
}https://stackoverflow.com/questions/3519184
复制相似问题