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

C#中的可空类型

时间:2014-10-22 17:18:34      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:blog   ar   sp   div   on   log   ad   new   as   

 public class Person {
        public DateTime birth;
        public DateTime? death;
        string name;
        public TimeSpan Age {
            get {
                if (!death.HasValue) {
                    return DateTime.Now - birth;
                }
                else {
                    return death.Value - birth;
                }
            }
        }
        //构造函数
        public Person(string name, DateTime birth,DateTime?death) {
            this.birth = birth;
            this.death = death;
            this.name = name;
        }
    }


Person tr = new Person("AAAA", new DateTime(1988, 12, 13),null);
            Person kk = new Person("BBBB", new DateTime(1912, 12, 13), new DateTime(1954, 12, 12));
            Console.ReadKey();

  

C#中的可空类型

标签:blog   ar   sp   div   on   log   ad   new   as   

原文地址:http://www.cnblogs.com/alphafly/p/4043468.html

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