zoukankan      html  css  js  c++  java
  • 第二节 5属性2 简单

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    
    //Red Gate's Reflector 反编译工具
    namespace _5属性2
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Person5 p = new Person5();
                //p.Age = 30;
                //Console.WriteLine(p.Age);
    
                //Person6 p = new Person6();
                //p.IncAge();
                //p.IncAge();
                //Console.WriteLine("年龄{0}",p.Age);
    
                Person7 p = new Person7();
                p.Age = 30;
                Console.WriteLine(p.Age);
    
                
                Console.ReadKey();
            }
        }
    
        class Person7 
        {
            public int Age
            {
                get;
                set;
            }
            public string Name
            {
                get;
                set;
            }
        }
    
        class Person6
        {
            private int age;
            public int Age //只读属性,没有赋值操作
            {
                get { return age; }
            }
            public void IncAge() 
            {
                age++;
            }
        }
    
        class Person5 
        {
            private int age;
            public int Age {
                set {
                    this.Age = value; //这里易错,列循环,如果直接把value值赋给this.Age的话,
                    //因为this.Age就是自己,然后就死循环了
                }
                get {
                    return this.Age;
                }
            }
        }
    }
    

      

  • 相关阅读:
    Diameter 消息格式解析
    我们活成了不想的样子
    《活着》片段
    我的庚子年
    <<甄嬛传>>后感
    对于根目录磁盘满的了问题
    phpstorm注册账号
    mac安装nginx
    samba文件共享及账户映射
    我们的读书会
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/2365933.html
Copyright © 2011-2022 走看看