📄 default.aspx
字号:
<%@Page Language="C#"%>
<script runat=server>
// Defines a product
public class Product
{
// Private members
string _code;
string _description;
double _price;
// Constructor
public Product( string initialCode,
string initialDescription,
double initialPrice)
{
Code = initialCode;
Description = initialDescription;
Price = initialPrice;
}
public string Description
{
get { return _description; }
set { _description = value; }
}
public string Code
{
get { return _code; }
set { _code = value; }
}
public double Price
{
get { return _price; }
set { _price = value; }
}
}
// Define a Products Collection
public class ProductCollection : IEnumerable
{
Hashtable _products;
public ProductCollection()
{
_products = new Hashtable();
}
// Implement an enumerator for the products
public IEnumerator GetEnumerator()
{
return _products.Values.GetEnumerator();
}
public Product this[ string Code ]
{
get { return (Product) _products[Code]; }
set { Add(value); }
}
public void Add( Product Item )
{
if ( Item == null )
throw new ArgumentException("Product can not be null");
_products.Add(Item.Code,Item);
}
public void Remove( Product Item )
{
_products.Remove( Item.Code );
}
}
</script>
<%
// List products where the price is greater than 40 dollars
ProductCollection products;
Product p;
products = new ProductCollection();
p = new Product("CAR", "A New Car", 19999.99 );
products.Add( p );
p = new Product("HOUSE", "A New House", 299999.99 );
products.Add( p );
p = new Product("BOOK", "A New Book", 49.99 );
products[p.Code] = p;
Response.Write("<h4>Product List</h4>");
foreach( Product p2 in products )
{
Response.Write (p2.Code + "-" + p2.Description + "-" + p2.Price );
Response.Write("<BR>");
}
products.Remove( products["HOUSE"] );
Response.Write("<h4>Product List (HOUSE removed)</h4>");
foreach( Product p2 in products )
{
Response.Write (p2.Code + "-" + p2.Description + "-" + p2.Price );
Response.Write("<BR>");
}
Response.Write("<p>");
Response.Write("<BR>Description for code CAR is:" +
products["CAR"].Description );
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -