public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Book b = new Book();
b.Fiction = false;
b.All();
}
}public class Book
{
private bool fiction; public bool Fiction
{
set
{
fiction = value;
}
get
{
bool zz = true;
return zz;
}
} public void All()
{
System.Web.HttpContext.Current.Response.Write(Fiction);
//如果取的是Fiction则显示true;
//System.Web.HttpContext.Current.Response.Write(fiction);
//把上面的Fiction改为fiction则显示的是false;
//为什么会这样显示?内部的运行机制是什么啊?
}
}
{
protected void Page_Load(object sender, EventArgs e)
{
Book b = new Book();
b.Fiction = false;
b.All();
}
}public class Book
{
private bool fiction; public bool Fiction
{
set
{
fiction = value;
}
get
{
bool zz = true;
return zz;
}
} public void All()
{
System.Web.HttpContext.Current.Response.Write(Fiction);
//如果取的是Fiction则显示true;
//System.Web.HttpContext.Current.Response.Write(fiction);
//把上面的Fiction改为fiction则显示的是false;
//为什么会这样显示?内部的运行机制是什么啊?
}
}
bool b = Fiction;//此时调用了get,get中始终返回true
System.Web.HttpContext.Current.Response.Write(b);而System.Web.HttpContext.Current.Response.Write(fiction);没有调用get,就返回fiction的值(false)如果改成:
public bool Fiction
{
set
{
fiction = value;
}
get
{
return fiction;
}
}
二者显示就一样了。
public class Book
{
private bool fiction; public bool Fiction
{
set
{
fiction = value;
}
get
{
return fiction;
}
}