C# 延迟处理类 Lazy

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lazy
{
    class Program
    {
        static void Main(string[] args)
        {
            School aa = new School();
            List<student> ass=aa.lazy_students.Value;
            foreach (var m in ass)
            {
                Console.WriteLine("姓名:{0} 年龄:{1},时间:{2}",m.name,m.age,m.date);
            }
            Console.ReadKey();
            
        }
    }
    public class School
    {
        public Lazy<List<student>> lazy_students { get; set; }

        public School()
        {
            lazy_students = new Lazy<List<student>>(() =>this.SetLazy());
        }
        private List<student> SetLazy()
        {
            List<student> ss = new List<student>{
            new  student{name="sx",age=18,date=DateTime.Now},
            new student{name="sb",age=19,date=DateTime.Now}
            
            
            };
            return ss;
        }
    }
    public class student
    {
        public string name { get; set; }
        public int age { get; set; }
        public DateTime date { get; set; }
    }
}
原文地址:https://www.cnblogs.com/soundcode/p/5310901.html