Constructor with parameter (C#)
<%@ page Language="c#" runat="server" %>
<script runat="server">
public class Book
{
private string title;
private int isbn;
private decimal price;
public Book(string newTitle, int newIsbn)
{
title = newTitle;
isbn = newIsbn;
}
public string TitleInfo
{
get
{
return title + " <i>[ISBN: " + isbn + "]</i>";
}
}
public string Title
{
get
{
return title;
}
}
public int Isbn
{
get
{
return isbn;
}
}
public decimal Price
{
get
{
return price;
}
set
{
price = value;
}
}
}
void Page_Load()
{
Book MyBook = new Book("Beginning ASP.NET 1.0 with C#", 1861007345);
Response.Write("<b>new book 'MyBook' created.</b>");
MyBook.Price = 39.99m;
Response.Write("<br/>Title info: " + MyBook.TitleInfo);
Response.Write("<br/>Price: $" + MyBook.Price + "<br/>");
Book AnotherBook = new Book("Professional ASP.NET 1.0 SE", 1861007035);
Response.Write("<b>new book 'AnotherBook' created.</b>");
AnotherBook.Price = 59.99m;
Response.Write("<br/>Title info: " + AnotherBook.TitleInfo);
Response.Write("<br/>Price: $" + AnotherBook.Price + "<br/>");
}
</script>
Related examples in the same category