假设有一个WebForm1.aspx,其中定义了类WebForm1。 但是下面的代码运行的结果却有点出乎意料: private void Page_Load(object sender, System.EventArgs e) { Response.Write(Object.ReferenceEquals(this.GetType(), typeof(WebForm1)).ToString()); //输出为false. } 原来aspx页面在运行的时候会动态产生一个派生类:ASP.WebForm1_aspx。运行时的实例对象是从那个派生类创建的。 因此上边的代码改成如下,输出就为true了。 private void Page_Load(object sender, System.EventArgs e) { Response.Write(Object.ReferenceEquals(this.GetType().BaseType, typeof(WebForm1)).ToString()); //输出为true. } 相关文章: