When to lazy load?

后端 未结 8 1886
庸人自扰
庸人自扰 2020-12-31 17:14

I lazy load all my members. I have been doing this for a while and simply taken lazy load to be a good thing at face value.

Let\'s say we have

publi         


        
8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 17:30

    this is not lazy loading.

    lazy loading would mean that you just load the value at the moment of a real access (which doesnt happen in the initializer)

    lazy loading is something like that:

    private SomeClass _someRef = null;
    public SomeClass SomeRef
    {
      get
      {
        if(_someRef == null)
        {
           //initialisation just in case of access
           _someRef = new  SomeClass();
        }
        return _someRef;
      }
    }
    

提交回复
热议问题