using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace On_Wednesday_17th_March
{
public class Person
{
private int age;
public int Age
{
get
{
return age;
}
set
{
if (value > 0 && value < 100)
{
age = value;
}
else
throw new Exception("Warning:The age is not between 0 and 100");
}
}
public Person()
{
}
public Person(int newAge)
{
age = newAge;
}
}
class Program
{
static void Main(string[] args)
{
Person person1 = new Person();
person1.Age = -10;
// 此时会抛出Exception;
Person person2 = new Person(-10);
//晕了,此时并没有丢出异常
/// 怎么会这样啊,希望高手指导下唉!
}
}
}