延迟加载 Lazy<T>的使用
有些变量声明了不一定用到,就白白占用系统资源了
var tmpSqlCells = new Lazy<BlockingCollection<ICell>>(); ... if(condition) { ... tmpSqlCells.Value.Add(item); //添加成员 } ... //遍历成员 foreach (var item in tmpSqlCells.Value.GetConsumingEnumerable()) { ... }
可见写和读中间都多了一层Value