这里几行错哪了?

来源:百度知道 编辑:UC知道 时间:2024/07/04 06:38:35
public partial class e : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Account a = new Account();
a.Withdraw(200.22);
}
public class Account
{
public void Withdraw(double amt)
{
Response.Write(amt);
}
}
}
----------------“Response”有波浪线,错误提示如下:
错误 1 Cannot access a nonstatic member of outer type 'System.Web.UI.Page' via nested type 'e.Account'

错在Response是外部类e的非静态成员,内部类是不可以直接访问的
解决可以这样作
protected void Page_Load(object sender, EventArgs e)
{

Account a = new Account(this);
a.Withdraw(200.22);
}
public class Account
{
Page p = new Page();
public Account(Page p) { this.p = p; }
public void Withdraw(double amt)
{
p.Response.Write(amt);
}
}

你为什么要2个类嵌套啊?