Anonymous Example In .Net 3.5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Lazy
new Lazy
BigInstance sdy = m_lazyInstance2.Value;
Lazy
new Lazy
BigInstance2 sdy2 = m_lazyInstance3.Value;
}
}
public class BigInstance
{
}
public class BigInstance2
{
}
public class Lazy
{
public Lazy(Func
{
this.m_initialized = false;
this.m_func = func;
this.m_mutex = new object();
}
private Func
private bool m_initialized;
private object m_mutex;
private T m_value;
public T Value
{
get
{
if (!this.m_initialized)
{
lock (this.m_mutex)
{
if (!this.m_initialized)
{
this.m_value = this.m_func();
this.m_func = null;
this.m_initialized = true;
}
}
}
return this.m_value;
}
}
}
}
0 Comments:
Post a Comment
<< Home