Mike Lindegarde... Online

Things I'm likely to forget.


Lazy Loading Properties with the Null-Coalescing Operator

Every now and again I want to lazily load a properties value using the null-coalescing operator.  Inevitably I've forgotten the proper syntax by the next time I want to use it:

public SomeObject PropertyName => 
    _someField ?? (_someField = _container.GetInstance<TObject>());