class Test
{
private int _aa;
public int AA
{
set
{
if (value > 100 || value < 0) value = 0;
_aa = value;
}
get
{
return _aa;
}
}
}
class Program
{
static void Main(string[] args)
{
Test t = new Test();
t.AA = 101;
Console.WriteLine(t.AA); //输出0
Console.ReadKey();
}
}
C# 简单的 get set
最新推荐文章于 2024-08-06 10:49:18 发布