Define and use class: property (C#) : Class Definition « Language Basics « ASP.Net






Define and use class: property (C#)

<%@ page Language="c#" runat="server" %>
<script runat="server">
public class Book
{
  private string title;
  private int isbn;
  private decimal price;
  public Book()
  {
    title = "Book";
    isbn = 099999999999;
  }

  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();
    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/>");
  }
</script>

           
       








Related examples in the same category

1.Define a class and display its value (C#)
2.Constructor with parameter (C#)
3.Define two classes (C#)