Home » .NET » C#: Lazy is not constrained to static contexts, instance field initializers are: via Stack Overflow

About Jeroen Pluimers

Jeroen Pluimers

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

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a sysadmin Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. Introduction to NGINX
2. Apache HTTP Server Cookbook
3. VirtualBox Essentials
4. Nagios Monitoring Cookbook
5. Linux BASH Programming Cookbook
6. Postgresql Database Tutorial
and many more ....
I agree to the Terms and Privacy Policy
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments