首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

.NET 4.0的推延初始化

2013-03-27 
.NET 4.0的延迟初始化延迟初始化意味着延迟一个对象,直到首次用它。主要用来提高性能,减少内存需要。using S

.NET 4.0的延迟初始化

延迟初始化意味着延迟一个对象,直到首次用它。主要用来提高性能,减少内存需要。

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace FirstConsoleApplication{    class Customer    {        public int Id { get; set; }        public string Name { get; set; }        public Customer(int Id, string Name)        {            this.Id = Id;            this.Name = Name;        }    }    class Program    {        static void Main(string[] args)        {            Lazy<Customer> cust = new Lazy<Customer>(() => new Customer(1, "Amit"));            DisplayCustomer(cust.Value);            Console.ReadLine();        }        public static void DisplayCustomer(Customer c)        {            Console.WriteLine(c.Id.ToString());            Console.WriteLine(c.Name.ToString());        }    }}


 

热点排行