public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerableList<T>继承了 ICollection 接口代码
List<int> list = new List<int>();怎么list点不出 "IsSynchronized"属性了,“IsSynchronized”跑那去了?

解决方案 »

  1.   

    先转换为 ICollection:
    List <int> list = new List <int>(); 
    bool b = ((System.Collections.ICollection)list).IsSynchronized;
    Console.WriteLine(b);
      

  2.   

    那应该是个bool值吧 要转换的吧
      

  3.   

    这个属性在List<T>对象中是继承自ICollection接口的显式实现...所以必须强制转换为ICollection接口才会有...另外...在List<T>的默认实现中,此属性始终返回false...
      

  4.   

    List <T>实现ICollection 接口中的IsSynchronized属性是显式接口实现,是private的,所以要访问此属性的话,要先强制转换为ICollection ,参考1楼
      

  5.   


    为什么要这样呢?Class 继承了接口,就得实现接口的方法和属性啊。List<int> list = new List<int>();
    实例化了 Class , 它就应该是 list的 属性啊
    如:
    public interface Test1
    {
        int Count {  get;}
    }public interface Test2 : Test1
    {
        bool IsTest { get;}
    }public class Test : Test2 
    {
        public bool IsTest
        {
            get { return  false; }
        }
        public int Count
        {
            get {return  0; }
        }}
    Test t = new Test();
            t.Count;
            t.IsTest;
      

  6.   

    它是list的属性...但是由于它是list对象具有的ICollection接口的显式实现成员,因此在实例成员中被隐藏...你最好去看一下MSDN,搞清楚“显式实现接口成员”的含义和意义...
    http://msdn.microsoft.com/zh-cn/library/ms229034(VS.80).aspx
      

  7.   


    我在“MSDN"文档中看到了,说它是“显示接口实现"但我在
    public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable
    {}
    没有看到?这是为什么呢?