《零基础学C#》第七章-实例02:通过属性检验商品库存的输入范围——练习2

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wtxhai/article/details/88741840
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Example702_02
{
    class Program
    {
        private int goods_num;   //定义字段
        private int Goods_Num   //定义属性
        {
            get   //设置get访问器
            {
                return goods_num;
            }
            set    //设置set访问器
            {
                if (value < 10)
                {
                    Console.WriteLine("库存不足,请及时补充!");
                }
                else if (value > 100)
                {
                    Console.WriteLine("库存冗余,请注意!");
                }
                else if (value > 0 && value < 100)
                {
                    Console.WriteLine("您的库存范围在正常内!");
                }
            }
        }
        static void Main(string[] args)
        {
            Program p = new Program();         //创建Program类的对象
            while (true)
            {
                Console.Write("请输入商品库存数量:");
                p.Goods_Num = Convert.ToInt32(Console.ReadLine());       //输入商品库存数量
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/wtxhai/article/details/88741840