예제 #1
0
 //Main_12_2_10
 public static void Main_12_2_10()
 {
     //定义基元类型
     var i = 100;
     var str = "Hello, world.";
     //定义数组类型
     var arr = new[] { "小王", "张三", "李四" };
     //定义自定义类型
     var user = new User { Name = "小王", Age = 27 };
     Console.WriteLine(i);
     Console.WriteLine(str);
 }
예제 #2
0
        //Main_12_2_4
        public static void Main_12_2_4()
        {
            var user = new User { Name = "小王", Age = 27 };
            Console.WriteLine(user.isName("小佳"));

            User user2 = new User { Name = "Emma", Age = 26 };
            //调用扩展方法
            user2.ShowInfo();

            string str = "123abc";
            //调用扩展方法
            str.TellType();
            //调用继承的扩展方法
            str.ShowType();
        }
예제 #3
0
        //Main_12_2_1
        public static void Main_12_2_1()
        {
            //2.0方式
            User user = new User();
            user.Name = "小王";
            user.Age = 27;

            //3.0方式
            User user3_0 = new User { Age = 27, Name = "小王" };

            //嵌套实现
            User user3 = new User { Name = "小王", Age = 27, UserInfo = new UserInfo { PhoneNo = 123456789, Emal = "*****@*****.**", IsVIP = true } };

            Console.WriteLine(user3.UserInfo.Emal);
        }