IList NotSupportedException IsReadOnly:是否只读

来源:互联网 发布:医用软件开发 书籍 编辑:程序博客网 时间:2024/05/29 18:25

在 .NET Framework 2.0 版中,Array 类实现 System.Collections.Generic.IList、System.Collections.Generic.ICollection 和System.Collections.Generic.IEnumerable 泛型接口。由于实现是在运行时提供给数组的,因而对于文档生成工具不可见。因此,泛型接口不会出现在Array 类的声明语法中,也不会有关于只能通过将数组强制转换为泛型接口类型(显式接口实现)才可访问的接口成员的参考主题。将某一数组强制转换为这三种接口之一时需要注意的关键一点是,添加、插入或移除元素的成员会引发NotSupportedException。 

Array 实现了Ilist 接口

因此 

IList<int> testArray = new int[]{1,2};

没有错误

但是

testArray.Add(3);

会抛出NotSupportedException 异常


IsReadOnly:是否只读

   IList<int> arrayIList = new int[] { 2, 3 };
            var isReadOnly = arrayIList.IsReadOnly;
            IList<int> realList = new List<int> { 3, 4 };
            var notReadOnly = realList.IsReadOnly;


参考文档:http://msdn.microsoft.com/zh-cn/library/system.array%28v=VS.80%29.aspx




原创粉丝点击