码迷,mamicode.com
首页 > Windows程序 > 详细

C# 延迟处理类 Lazy

时间:2016-03-23 14:25:05      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:

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; }
    }
}

C# 延迟处理类 Lazy

标签:

原文地址:http://www.cnblogs.com/soundcode/p/5310901.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!