1.采用从CollectionBase抽象基类继承的方式实现Product集合类:
           以数字做为索引值,详细成员查看msdn,还有更多的重载函数
 1 using System;
 2 using System.Collections;    
 3 public class productCollection:CollectionBase     
 4 {
 5     public void Add(product newProduct)//添加类对象重载函数         
 6     {              
 7         List.Add(newProduct);         
 8     }         
 9     public void Remove(product oldProduct)//移除类对象重载函数 
10     {              
11         List.Remove(oldProduct);         
12     }         
13     public product this[int productIndex]//索引器重载函数
14     {              
15         get{                   
16             return (product)List[productIndex];              
17         }              
18         set{                   
19             List[productIndex]=value;              
20         }         
21     }     
22 }


2.采用从DictionaryBase抽象基类继承的方式实现Product集合类:
         以字符串做为索引值,详细成员查看msdn,还有更多的重载函数

 1 using System;
 2 using System.Collections; 
 3 public class ShortStringDictionary : DictionaryBase  {      
 4     public String this[ String key ]  //索引器重载函数     
 5     {         
 6         get{              
 7             return( (String) Dictionary[key] );         
 8         }         
 9         set{              
10             Dictionary[key] = value;         
11         }     
12     }       
13     public void Add( String key, String value )  //添加类对象重载函数     
14     {         
15         Dictionary.Add( key, value );     
16     }       
17     public void Remove( String key )  //移除类对象重载函数     
18     {         
19         Dictionary.Remove( key );     
20     }     
21 


 

posted on 2006-07-22 16:37  FireYang  阅读(801)  评论(0编辑  收藏  举报