zoukankan      html  css  js  c++  java
  • 代码清单4-4 Person类的部分代码,其中包含了年龄的计算

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Person turing = new Person("Alan Turing", new DateTime(1912, 6, 3), new DateTime(1954, 6, 7));
                Person knuth = new Person("Donald Knuth", new DateTime(1938, 1, 10), null);
                Console.ReadKey();
            }
    
            class Person
            {
                DateTime birth;
                DateTime? death;
                string name;
                public TimeSpan Age
                {
                    get
                    {
                        if (death == null)
                        {
                            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;
                }
            }
        }
    }
  • 相关阅读:
    Vue框架之基础知识
    Vue框架之初识
    Django组件之modelformset
    Django之小结
    Django组件之modelform
    Django之form表单详解
    jquery基础知识2
    jQuery基础知识1
    js基础知识4
    js基础知识3
  • 原文地址:https://www.cnblogs.com/liuslayer/p/6963947.html
Copyright © 2011-2022 走看看