问题补充:
protected void Button1_OnClick(object sender, EventArgs e)
{
List<a> list=new List<a>();
list.Add(new a("b"));//这样不会报错
list.Add(new b("c"));
//如果ab顺序对调 活着一个b 一个c就会报错
GridView1.DataSource = list;
GridView1.DataBind();
}
public class a
{
public a() { }
public a(string a) { this.aa = a; }
public virtual string aa { get; set; }
}
public class b : a
{
public b(string aa) { this.aa = aa; }
public override string aa
{
get
{
return base.aa;
}
set
{
base.aa = value;
}
}
}
public class c : a
{
public c(string aa) { this.aa = aa; }
public override string aa
{
get
{
return base.aa;
}
set
{
base.aa = value;
}
}
}