.NET 4.0 New Feature - Generic Lazy class
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Lazy<Boolean> lazy = new Lazy<Boolean>(() => { Console.WriteLine(“Initializing…”); System.Threading.Thread.Sleep(10000); Console.WriteLine(“Initialized…”); return true; });
Console.WriteLine("IsValueCreated = {0}", lazy.IsValueCreated);
Stopwatch sw = Stopwatch.StartNew();
Console.WriteLine("result = {0}", lazy.Value);
//Console.WriteLine("result = {0}", lazy.ToString());
Console.WriteLine("Elapsed Time = {0} ms", sw.ElapsedMilliseconds);
Console.WriteLine(new string('=', 50));
Console.WriteLine("IsValueCreated = {0}", lazy.IsValueCreated);
sw.Restart();
Console.WriteLine("result = {0}", lazy.Value);
//Console.WriteLine("result = {0}", lazy.ToString());
Console.WriteLine("Elapsed Time = {0} ms", sw.ElapsedMilliseconds);
}
}
}
public int[] Stocks { get { return _stocks.Value; } }
}
...
static void Main(string[] args)
{
Person p = new Person();
System.Console.WriteLine(string.Join(",", p.Stocks.Select((value) => { return value.ToString(); })));
}</pre>