Quick .NET 4.5 tip: Using lazy initialization for your objects with the new LazyInitializer class

Posted: (EET/GMT+2)

 

Quick development tip for today: how do you make sure your objects are initialized when you need them? Personally, I'm using anything from simple if statements to factory classes, but most often, it's enough to take the simplest route. When the last time I needed to do this, I wanted to try the new class called LazyInitializer that is available in .NET 4.5. This class is available on the desktop, but also in Windows 8 Store applications.

If you are looking for an easy, built-in way to make sure your objects are initialized but don't want to do initialization too early (in case you won't need the objects anyway), try this new class.

Happy hacking!