c#中属性的声明和保护

weblog 3157 0 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            Student s = new Student();
            s.Age = 1000;
            Console.WriteLine("123");
        }
    }

    class Student
    {
        private int age;

        public int Age
        {
            get { return age; }
            set {
                if (age>0&&age<120)
                {
                    age = value;
                }else
                {
                    throw new Exception("age error");
                }
             }
        }

        public Boolean canWork
        {
            get
            {
                if (age>16)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
    }
}

快捷键:输入propfull按tab键


猜你喜欢
weblog 3375 String类实现及其不可变 对于String类实现从源码可以看出,String类底层维着一个final修饰char数组,用来储存字符。并且除了hash这个其它
weblog 2198 vue计算监视!DOCTYPEhtmlhtml head metacharset="UTF-8" title/title scriptsrc="js/vue.min.js
其他 2231 事件例子usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text
weblog 3034 c#数据类型 c#数据类型分为值类型引用类型 值类型有包括(结构体类型,枚举类型) 引用类型又包括(类类型,数组类型,接口类型,委托类型) c#数据类型派生谱系 值类型
spring/springmvc 2070 yml配置文件:sys:qq_back:http://www.123.club/indexesqq_appid:1018qq_appkey:025bf1d0配置类publicclassSystemStaticConstant{ privatestaticStringqq_back; privatestaticStringqq_appid; privatestaticStringqq_appke
linux系统 3566 ctrl+cctrl+z都是断命令,但是他们作用却不一样.ctrl+c强制断程序ctrl+z是将任务断,挂起状态,ctrl+c是强制断程序执行。ctrl+z是将任务断.但是此任
weblog 3605 SQL是一种式语言SQL语言是为计算机了一个你想从原始数据获得什么样结果一个范例,而不是告诉计算机如何能够得到结果。SQL语言是结果集,计算机会根据SQL所内容来从数
weblog 2231 一个案例说#includeiostreamusingnamespacestd;/**定义函数指针*///typedef为一个指针函数类型MethodPointer//int为指针指向函数返回
目录
没有一个冬天不可逾越,没有一个春天不会来临。最慢的步伐不是跬步,而是徘徊,最快的脚步不是冲刺,而是坚持。