延迟加载 Lazy<T>的使用

有些变量声明了不一定用到,就白白占用系统资源了

 var tmpSqlCells = new Lazy<BlockingCollection<ICell>>();
...
if(condition)
{
       ...
       tmpSqlCells.Value.Add(item);
       //添加成员
}   
...
//遍历成员
 foreach (var item in tmpSqlCells.Value.GetConsumingEnumerable())
{
    ...
}

可见写和读中间都多了一层Value

 

posted on 2017-09-21 09:12  吃肉不吃菜  阅读(158)  评论(0编辑  收藏  举报

导航