懒惰属性应该返回Value还是Lazy(of Value)?

时间:2016-04-25 14:00:46

标签: .net vb.net properties lazy-initialization

我有一个懒惰的属性,在第一次访问时构造了值:

<div>
  <ul>
    <li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li><li></li>
  </ul>
</div>

由于private readonly ValueLazy as Lazy(of integer) public readony property Value as integer get return ValueLazy.Value end get end property public sub new(Service as IService) me.ValueLazy = new Lazy(of integer)(function() Service.GetInteger) end sub 请求实际值,因此构建属性值可能需要一些时间。这似乎违反了属性获取者应该快速并且做最少工作的规则。

属性是否真的会返回值(例如Service)?

或者属性应该返回延迟值(例如Integer)?

Lazy(of Integer)

0 个答案:

没有答案
相关问题