Wednesday, May 18, 2011

Lazy in C#

If you want to initialize a class as lazy Initialization you can go with Lazy key word.

Lazy _expensive = new Lazy
(() => new Expensive(), true);

Note: If you pass true as parameter,it will be thread safe else as false, it will not be thread safe.

If for a single -thread or single ton class Lazy is best

No comments:

Post a Comment