首页 > Windows开发 > 详细

C#中的可空类型

时间:2014-10-22 17:17:30      阅读:293      评论:0      收藏:0      [点我收藏+]
 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#中的可空类型

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!