NET岛

导航

继承 System.Collections.CollectionBase 创建一个强类型集合类

using System;

namespace Joe_s_Doughnut_Shop_CSharp
{
    
/// <summary>
    
/// Summary description for DoughnutCollection.
    
/// </summary>

    public class DoughnutCollection : System.Collections.CollectionBase
    
{
        
public DoughnutCollection()
        
{
            
//
            
// TODO: Add constructor logic here
            
//
        }
          //添加对象
        
public void Add(DoughnutMachine.Doughnut aDoughnut)
        
{
            List.Add(aDoughnut);
        }
          //索引器
        
public DoughnutMachine.Doughnut this[int index]
        
{
            
get
            
{
                
return (DoughnutMachine.Doughnut)List[index];
            }

        }
        //移除对象
        
public void Remove(DoughnutMachine.Doughnut aDoughnut)
        
{
            
if (List.Contains(aDoughnut) == true)
            
{
                List.Remove(aDoughnut);
            }

        }

    }

}

posted on 2005-08-21 23:19  左佩玉  阅读(689)  评论(0编辑  收藏  举报