using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class lei_jichu : System.Web.UI.Page
{
public class Book
{
string title;
int num;
double price;
public delegate void TitleChengHendler(); //事先申明一个委托,可在类外部申明
public event TitleChengHendler TitleCheng; //申明一个事件并指定它的委托类型
public Book()
{
}
poublic Book(string ntitle, int nnum, double nprice)
{
title = ntitle;
num = nnum;
price = nprice;
}
public string Title
{
get
{
return title;
}
set
{
title = value;
TitleCheng(); //触发事件
}
}
public int Num
{
get
{
return num;
}
set
{
num = value;
}
}
public double price
{
get
{
return price;
}
set
{
price = value;
}
}
public string BookInfo()
{
string Html = "书名是:" + title + "<br/>库存:" + num + "<br/>价格:" + price + "元/本";
return Html;
}
}
protected void Page_Load(object sender, EventArgs e)
{
Book shu = new Book();
shu.TitleCheng += new Book.TitleChengHendler(shu_TitleCheng);
shu.Title = "高等代数";
shu.Num = 5000;
shu.Price = 20;
Response.Write(shu.BookInfo() );
}
void shu_TitleCheng()
{
Response.Write("事件开始执行了<br/>");
}
}
using System.Web.UI.HtmlControls;
public partial class lei_jichu : System.Web.UI.Page
{
public class Book
{
string title;
int num;
double price;
public delegate void TitleChengHendler(); //事先申明一个委托,可在类外部申明
public event TitleChengHendler TitleCheng; //申明一个事件并指定它的委托类型
public Book()
{
}
poublic Book(string ntitle, int nnum, double nprice)
{
title = ntitle;
num = nnum;
price = nprice;
}
public string Title
{
get
{
return title;
}
set
{
title = value;
TitleCheng(); //触发事件
}
}
public int Num
{
get
{
return num;
}
set
{
num = value;
}
}
public double price
{
get
{
return price;
}
set
{
price = value;
}
}
public string BookInfo()
{
string Html = "书名是:" + title + "<br/>库存:" + num + "<br/>价格:" + price + "元/本";
return Html;
}
}
protected void Page_Load(object sender, EventArgs e)
{
Book shu = new Book();
shu.TitleCheng += new Book.TitleChengHendler(shu_TitleCheng);
shu.Title = "高等代数";
shu.Num = 5000;
shu.Price = 20;
Response.Write(shu.BookInfo() );
}
void shu_TitleCheng()
{
Response.Write("事件开始执行了<br/>");
}
}