class Person
{
private int age;
public int Age
{
get { return age; }
set { age = value; }
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine(GetPerson().Age);
Console.ReadKey();
}
static Person GetPerson()
{
Person p = new Person();
p.Age = 8;
try
{
p.Age++;
Console.WriteLine("a");
return p;
}
finally
{
Console.WriteLine("b");
p.Age++;
}
}
}
ab10,,,,,是吗?
try{
}catch{}
finally的使用
理解finally,不管是否catch到异常,它都会被执行