以下创建了一个Person类型的强类型化集合。

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;

/// <summary>
/// PersonList 的摘要说明
/// </summary>
public class PersonList:System.Collections.IEnumerable
{
    private ArrayList innerList=new ArrayList();

    public PersonList()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    public void Add(Person aPerson)
    {
        innerList.Add(aPerson);
    }

    public void Remove(Person aPerson)
    {
        innerList.Remove(aPerson);
    }

    public int Count
    {
        get
        {
            return innerList.Count;
        }
    }

    public Person this[int index]
    {
        get {
            return (Person)innerList[index];

        }
        set
        {
            innerList[index] = value;
        }
    }
    public IEnumerator GetEnumerator()
    {
        return innerList.GetEnumerator();
    }


}
 


本文转载:CSDN博客