Lecture05 - ITE 5230
Lecture05 - ITE 5230
1
Chapter 12
How to create
and use classes
public Product(){}
namespace ProductMaintenance
{
class Product
{
}
}
public Product()
{
}
A read/write property
public string Code
{
get { return code; }
set { code = value; }
}
A read-only property
public decimal DiscountAmount
{
get
{
discountAmount = subtotal * discountPercent;
return discountAmount;
}
}
Note
You don’t need to know how the ProductDB class works. You
just need to know about its methods so you can use them in your
code.
DialogResult button =
MessageBox.Show(message, "Confirm Delete",
MessageBoxButtons.YesNo);
if (button == DialogResult.Yes)
{
products.Remove(product);
ProductDB.SaveProducts(products);
FillProductListBox();
}
}
}
An auto-implemented property
with both get and set accessors
public string Code { get; set; }
An auto-implemented property
with a get accessor and an initial value
public string Code { get; } = "CS15";
*Community Edition doesn’t have the CodeLens feature that lets you
display references.
// Call a method
string msg = p.GetDisplayText("\n");
How to work
with indexers, delegates,
events, and operators
public ProductList()
{
products = new List<Product>();
}
Binary operators
+ - * / % & | == != > < >= <=
public ProductList()
{
products = new List<Product>();
}
if (button == DialogResult.Yes)
{
products -= product;
}
}
}