- using System;
- namespace LazyExample
- {
- class Program
- {
- static void Main(string[] args)
- {
- Lazy<Customer> lazyCustomer = new Lazy<Customer>();
- Console.WriteLine(string.Format("Is customer initialized :{0}", lazyCustomer.IsValueCreated));
- Customer customer = lazyCustomer.Value;
- Console.WriteLine(string.Format("Is string value initialized :{0}", lazyCustomer.IsValueCreated));
- }
- }
- public class Customer
- {
- public Customer()
- {
- Console.WriteLine("Customer Intialized");
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/2408201513524.html
来源: http://www.codesnippet.cn/detail/2408201513524.html