版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wtxhai/article/details/88740934
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Example702_01
{
class Program
{
private int goods_num; //定义字段
private int Goods_Num //定义属性
{
get //设置get访问器
{
return goods_num;
}
set //设置set访问器
{
if (value > 0 && value < 100)
{
goods_num = value; //如果数据合理将会对其进行赋值
}
else
{
Console.WriteLine("库存数据不合理!");
}
}
}
static void Main(string[] args)
{
Program p = new Program(); //创建Program类的对象
while (true)
{
Console.Write("请输入商品库存数量:");
p.Goods_Num = Convert.ToInt32(Console.ReadLine()); //输入商品库存数量
}
}
}
}