コード例 #1
0
        public static void Run()
        {
            //Point a = new Point();
            PointVal a;

            a.X = 3;
            a.Y = 5;

            PointVal b = a;

            b.X = 7;
            b.Y = 10;

            a.LogValues();
            b.LogValues();

            //

            PointRef c = new PointRef()
            {
                X = 3, Y = 5
            };

            //c.X = 3;
            //c.Y = 5;

            PointRef d = c;

            d.X = 7;
            d.Y = 10;

            c.LogValues();
            d.LogValues();
        }
コード例 #2
0
        private static void NullRefExceptionNullable()
        {
            //tell about nulls
            PointRef c = null;

            Console.WriteLine(c.X);       //exception

            PointVal?nulllableVal = null; //useful when we fetch data from a databse and the field is null in db

            if (nulllableVal.HasValue)
            {
            }
            //or
            PointVal defaultVal = nulllableVal.GetValueOrDefault();
        }