Akbard,
I just wanted to let you know that I had a hard time with that one too. It just for some reason would not work, so I have a work around that I think is much better anyways. Here you go. I put this in its own class.
namespace Book_Object
{
public class Book
{
public Book(string newTitle, int newISBN, decimal newPrice) // Class Constructor
{
title = newTitle;
isbn = newISBN;
price = newPrice;
ukPrice = .25m;
canPrice = .15m;
}
private string title; // title Variable
private int isbn; // isbn Variable
private decimal price; // price Variable
private decimal ukPrice; // uk Price Variable
private decimal canPrice; // canadian Price Variable
public string US
{
get
{
return "US $" + Convert.ToString(price);
}
}
public string UK
{
get
{
return "UK $" + Convert.ToString(ukPrice = price - (price * ukPrice));
}
}
public string Can
{
get
{
return "CAN $" + Convert.ToString(canPrice = price + (price * canPrice));
}
}
public string TitleInfo
{
get
{
return title + " <i>[ISBN: " + isbn + "] </i>";
}
}
public string Title
{
get
{
return title;
}
}
public int ISBN
{
get
{
return isbn;
}
}
}
}
And now the other page looks like this
public class Book_Object : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Book MyBook = new Book("Beginning ASP.Net with C#", 1861007045, 39.99m);
Response.Write("<b>New book 'MyBook' created.</b>");
Response.Write("<br/>Title Info: " + MyBook.TitleInfo);
Response.Write("<br/>" + MyBook.US + "<br/>");
Response.Write(MyBook.UK + "<br/>");
Response.Write(MyBook.Can + "<br/><br/>");
Book AnotherBook = new Book("Professional ASP.Net 1.0 SE", 1861007035, 59.99m);
Response.Write("<b>New book 'AnotherBook' Created.</b>");
Response.Write("<br/>Title Info: " + AnotherBook.TitleInfo);
Response.Write("<br/>" + AnotherBook.US + "<br/>");
Response.Write(AnotherBook.UK + "<br/>");
Response.Write(AnotherBook.Can + "<br/><br/>");
}
}
I hope this helps you out.
Jason
"Is the glass half empty, half full, or twice as large as it needs to be?"
|