C#中的可空类型

 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#中的可空类型

上一篇:无法解析的外部符号 _WinMain@16


下一篇:ExtJs自学教程(1):一切从API開始