using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication16
{
class Program
{
static void Main(string[] args)
{
People people = new People(5);
people.Age = 100;
Console.WriteLine(people.GetAge());
Console.Read();
}
}
class People
{
int age;
public int Age
{
set
{
//value是类中age的原型,如果用自身的age是无法赋值的;
age=value+10;
}
get
{
return age-10;
}
}
public People(int a)
{
age = a;
}
public int GetAge()
{
return age;
}
}
}
//用get set 方法可以比较好的保护成员,又可以通过一定途径修改,提高封装性