.NET 4.0 has a nice utility class called System.Lazy that does lazy object initialization. I would like to use this class for a 3.5 project. One time I saw an implementation somewhere in a stackoverflow answer but I can't find it anymore. Does someone have an alternative implementation of Lazy? It doesn't need all the thread safety features of the framework 4.0 version.
Updated:
Answers contain a non thread safe and a thread safe version.
If you don't need thread-safety, it's pretty easy to put one together with a factory method. I use one very similar to the following:
Some funny (but not very usable) stuff can be added: implicit coversion from delegate:
And usage
C# compiler have some problem with performing this conversion, for example assigning lambda expression does not work, but it is one more thing causes your colleguas to think a bit :)
A somewhat simplify version of aaron's
Here is an implementation that I use.