源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-10-07 08:44 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:C#中怎么将一个List转换为只读的
如题,主要使用AsReadOnly这个方法就可以了
[u]复制代码[/u] 代码如下:
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);
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部