用户登录
用户注册

分享至

C#中怎么将一个List转换为只读的

  • 作者: 较劲_麻黄素
  • 来源: 51数据库
  • 2021-11-01
如题,主要使用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);
软件
前端设计
程序设计
Java相关