Age Calculation with nullable death date : nullable « Data Type « C# / CSharp Tutorial






using System;
using System.ComponentModel;

        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;
            }

            public static void Main()
            {
                Person turing = new Person("A",new DateTime(1913, 2, 23),new DateTime(1954, 6, 7));
                Person knuth = new Person("D",new DateTime(1978, 1, 10),null);
            }
       }








2.58.nullable
2.58.1.Box and unbox for nullable value
2.58.2.Boxing And Unboxing for nullable type
2.58.3.Age Calculation with nullable death date
2.58.4.Convert nullable value to string
2.58.5.Does Nullable value has value
2.58.6.Function for getting Nullable double value
2.58.7.Get hash code for nullable value
2.58.8.Get value or default value for nullable value
2.58.9.Nullable Class Members
2.58.10.Nullable Try Parse
2.58.11.Nullable integer Demo
2.58.12.Nullable value based vector
2.58.13.Partial Comparer for nullable value
2.58.14.Provide default value for nullable value
2.58.15.Reference Compare for nullable value
2.58.16.Using the Nullable Modifier