Exemplo n.º 1
0
        private static void Main(string[] args)
        {
            #region 引用类型

            //string txt=null;
            //var txt2 = txt;
            //Console.WriteLine(txt);

            #endregion

            #region 可空修饰符

            //int? count = null;
            //if (count == null)
            //{
            //    Console.WriteLine("null");
            //}
            //else
            //{
            //    Console.WriteLine("not null");
            //}

            #endregion

            #region 显示转换

            //checked
            //{
            //    long a = long.MaxValue;
            //    int b = (int)a;
            //    Console.WriteLine(b);
            //}

            #endregion

            #region 空结合运算符

            //checked
            //{
            //    string a = null;
            //    string b = a ?? "c";
            //    Console.WriteLine(b);
            //}

            #endregion

            #region 属性验证

            //Employee employee = new Employee();
            //employee.Initialize("aaa");
            ////employee.FirstName = "aaa";
            //Console.WriteLine(employee.FirstName);

            #endregion

            #region 聚合

            //Content content = new Content();
            //content.internalperson = new Person();
            //content.Name = "Yao Ming";
            //Console.WriteLine(content.internalperson.FirstName);

            #endregion

            #region 封箱拆箱

            var angel = new Angel();
            angel._Hours = 10;
            object objectAngel = angel;
            Console.WriteLine(((Angel)objectAngel)._Hours);

            ((Angel)objectAngel).MoveTo(12);
            Console.WriteLine(((Angel)objectAngel)._Hours);

            ((IAngel)angel).MoveTo(12);
            Console.WriteLine(angel._Hours);

            ((IAngel)objectAngel).MoveTo(12);
            Console.WriteLine(((Angel)objectAngel)._Hours);

            #endregion

            Console.Read();
        }
Exemplo n.º 2
0
        private static void Main(string[] args)
        {
            #region 引用类型

            //string txt=null;
            //var txt2 = txt;
            //Console.WriteLine(txt);

            #endregion

            #region 可空修饰符

            //int? count = null;
            //if (count == null)
            //{
            //    Console.WriteLine("null");
            //}
            //else
            //{
            //    Console.WriteLine("not null");
            //}

            #endregion

            #region 显示转换

            //checked
            //{
            //    long a = long.MaxValue;
            //    int b = (int)a;
            //    Console.WriteLine(b);
            //}

            #endregion

            #region 空结合运算符

            //checked
            //{
            //    string a = null;
            //    string b = a ?? "c";
            //    Console.WriteLine(b);
            //}

            #endregion

            #region 属性验证

            //Employee employee = new Employee();
            //employee.Initialize("aaa");
            ////employee.FirstName = "aaa";
            //Console.WriteLine(employee.FirstName);

            #endregion

            #region 聚合

            //Content content = new Content();
            //content.internalperson = new Person();
            //content.Name = "Yao Ming";
            //Console.WriteLine(content.internalperson.FirstName);

            #endregion

            #region 封箱拆箱

            var angel = new Angel();
            angel._Hours = 10;
            object objectAngel = angel;
            Console.WriteLine(((Angel) objectAngel)._Hours);

            ((Angel) objectAngel).MoveTo(12);
            Console.WriteLine(((Angel) objectAngel)._Hours);

            ((IAngel) angel).MoveTo(12);
            Console.WriteLine(angel._Hours);

            ((IAngel) objectAngel).MoveTo(12);
            Console.WriteLine(((Angel) objectAngel)._Hours);

            #endregion

            Console.Read();
        }