手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#中怎么将一个List转换为只读的
C#中怎么将一个List转换为只读的
摘要:如题,主要使用AsReadOnly这个方法就可以了复制代码代码如下:Lista=newList{1,2,3,4,5};IListb=a.As...

如题,主要使用AsReadOnly这个方法就可以了

复制代码 代码如下:

List<int> a = new List<int> {1, 2, 3, 4, 5};

IList<int> b = a.AsReadOnly(); // block modification...

IList<int> c = b.AsWritable(); // ... but unblock it again

c.Add(6);

Debug.Assert(a.Count == 6); // we've modified the original

IEnumerable<int> d = a.Select(x => x); // okay, try this...

IList<int> e = d.AsWritable(); // no, can still get round it

e.Add(7);

【C#中怎么将一个List转换为只读的】相关文章:

c#中Linq to Sql 增删除的实例

C#进制之间的相互转换详解

C# 判断字符串第一位是否为数字

C#中将ListView中数据导出到Excel的实例方法

C#中一些你可能没用过的调试窗口的方法

深入C#中get与set的详解

C#中使用快速排序按文件创建时间将文件排序的源码

C#中事件处理的个人体会

将字符串转换成System.Drawing.Color类型的方法

基于.net中突破每客户端两个http连接限制的详细介绍

精品推荐
分类导航