zoukankan      html  css  js  c++  java
  • 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; }
        }
    }
  • 相关阅读:
    条件
    循环
    列表
    字典
    集合
    公共操作
    函数-2
    函数-1
    函数加强
    文件操作
  • 原文地址:https://www.cnblogs.com/soundcode/p/5310901.html
Copyright © 2011-2022 走看看