.NET
C#: Lazy is not constrained to static contexts, instance field initializers are: via Stack Overflow
Lazy<T> is not constrained to static contexts.
Instance field initialisers cannot use instance references (but can use static references) as they run outside of the constructor.Though there are arguments for instance field initializers too., I think this is a good reason to initialize fields inside the constructor: there you do have access to instance references (but should not call virtual instance methods or properties) which leads to another reason: consistency as field initializers run in the opposite hierarchy order as constructors (incidentally causing this virtual method restriction).
Boy, that was a long sentence
Reference: | C#: Lazy is not constrained to static contexts, instance field initialisers are: via Stack Overflow from our NCG partner Jeroen Pluimers at the The Wiert Corner blog. |