class Person
{
private string _Name; public string Name
{
get { return _Name; }
set { _Name = value; }
} private int _Age; public int Age
{
get { return _Age; }
set { _Age = value; }
} public Person(string name, int age)
{
this.Name = name;
this.Age = age;
}
public Person()
{ }
}class Student:Person
{
public void SayHi()
{
Console.WriteLine("My name in student is {0} ,and My age is {1} .", Name, Age);
}
}
class Program
{
static void Main()
{
Person p = new Student();//大家看见没有,这样也可以啊,
//我想问问高手,C#有这个功能的话,主要的用途时什么呢?????????????
}
}
不过我这么用的时候Person一般都是接口。
就是说规定一个接口,N个实现类。根据情况用不同的实现类。