面向对象的特性 方法 属性 事件

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            /*School school1 = new School();
            school1.schoolname = "河北软件职业技术学院";
            school1.schooladdress = "保定市北市区职大路1号";
            school1.schoolarea = 100;
            school1.inschool = 10000;


            School school2 = new School();
            school1.schoolname = "清华大学";
            school1.schooladdress = "北京市海淀区圆明园路";
            school1.schoolarea = 1000;
            school1.inschool = 20000;*/


            School school3 = new School();

            /*school3.SetSchoolArea(400);
            school3.SchoolName = "河北大学1";
            Console.WriteLine(school3.SchoolName);

            school3.Yingjian = "不硬";
            Console.WriteLine(school3.Yingjian);*/

            school3.InSchool = 400;
            Console.WriteLine(school3.InSchool);
            //Console.WriteLine(school3.GetSchoolArea());
            Console.ReadKey();
        }
    }

    class School
    {
        private string schoolname;

        public string SchoolName
        {
            set
            {
                if (value == "河北大学")
                {
                    schoolname = value;
                }
                else
                {
                    schoolname = "您选择的学校不存在";
                }
            }
            get { return schoolname; }
        }
        private string schooladdress;

        private double schoolarea;

        private int inschool;//在校人数
        public int InSchool
        {
            get { return InSchool; }
            set { InSchool = value; }
        }

        private string _yingjian;
        public string Yingjian { get { return _yingjian; } set { _yingjian = value; } }


        public string Ruanjian { get; set; }//仅仅是为了开发者书写方便

        /*public string schoolname;
        public string schooladdress;
        public double schoolarea;
        public int inschool;//在校人数*/

        //为字段赋值
        public void SetSchoolArea(double area)
        {
            if (area > 10 && area < 1000)
            {
                schoolarea = area;
            }
        }
        //取值
        public double GetSchoolArea()
        {
            return schoolarea;
        }

        private void Kaixue()
        {

        }
        private void Zhaosheng()
        { }
        private void Shoufei()
        { }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值