111,128
社区成员
发帖
与我相关
我的任务
分享using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace delete
{
class Program
{
static void Main(string[] args)
{
liweike a = new liweike();
a.MyIntProp = 100; //这样才是执行了 set
Console.WriteLine(a.MyIntProp);
}
}
class liweike
{
private int li = 22;
private int myInt = 112;
public int MyIntProp
{
get
{
return myInt;
}
set
{
try
{
if (value >= 0 && value <= 10)
myInt = value;
else
throw (new ArgumentOutOfRangeException());
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}
}