C# Lazy Loaded Automatic Properties

前端 未结 12 2185
执笔经年
执笔经年 2020-12-04 11:08

In C#,

Is there a way to turn an automatic property into a lazy loaded automatic property with a specified default value?

Essentially, I am trying to turn th

12条回答
  •  无人及你
    2020-12-04 12:01

    Probably the most concise you can get is to use the null-coalescing operator:

    get { return _SomeVariable ?? (_SomeVariable = SomeClass.IOnlyWantToCallYouOnce()); }
    

提交回复
热议问题