C#之类的使用

属性与字段的使用类似iOS

    class Class1 {
        //字段私有,属性公有
        private string _name;
        private int _age;
        public string Name {
            set {
                _name = value;
            }
            get {
                return _name;
            }
        }
        public int Age {
            set {
                _age = value;
            }
            get {
                return _age;
            }
        } 

        public void Function() {

            Console.WriteLine("姓名{0},年龄{1}",this.Name,this.Age);
        }      

    }
时间: 2024-08-26 06:36:12