小弟是初学者,请教一个初级问题,请高手指教。
本人对于类的东西没怎么看懂,望高手教我。我试了一下,似乎类名book必须与下面的public Book(string newtitle,string newisbn)相同,这样后面的Book dx1 = new Book("cet-6词汇", "00-21-45698-3");才有效,这是什么原因呢?public class Book
{ //申明变量
private string title;
private string isbn;
private double price;
//构造函数逻辑
public Book(string newtitle,string newisbn)
{
title=newtitle;
isbn=newisbn;
}
public string TitleInfo
{
get
{
return "书名是:" + title + "<br>标签号是:" + isbn ;
}
}
public string Title
{
get
{
return title;
}
}
public double Price
{
get
{
return price;
}
set
{
price = value;
}
}
}
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Book dx1 = new Book("cet-6词汇", "00-21-45698-3");
dx1.Price = 18.00;
Response.Write(dx1.TitleInfo);
Response.Write("<br>价格是:" + dx1.Price );
}
}