C# 简单的 get set

来源:互联网 发布:随机数抽奖软件 编辑:程序博客网 时间:2024/05/18 12:33
    class Test    {        private int _aa;        public int AA         {            set            {                if (value > 100 || value < 0) value = 0;                _aa = value;            }            get            {                return _aa;            }        }    }    class Program    {        static void Main(string[] args)        {            Test t = new Test();            t.AA = 101;            Console.WriteLine(t.AA);   //输出0            Console.ReadKey();        }    }
0 0
原创粉丝点击