Categories
.NET C#

Lazy Loading with the Lazy class

Did you know the Lazy class in the System namespace?

This little useful helper was introduced with .NET 4. You can use it to lazy initialize properties.

The ResolvePackagePath()-method gets called if the value is needed the first time.
The property IsValueCreated lets you check if the value is already initialized.

Leave a Reply

Your email address will not be published. Required fields are marked *