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; }
}
}
上一篇:Atiti 重定向标准输出到字符串转接口adapter stream流体系 以及 重定向到字符串


下一篇:(六)jdk8学习心得之Stream流