【发布时间】:2011-09-15 16:02:26
【问题描述】:
我有一些代码我总是用来收集我的对象。这段代码在我的一些项目中被使用了 10 次,并替换了对象。
有什么方法可以将它创建为一个可以接受任何对象的函数?我听说过<T>,但我不确定如何在其中使用它。
public class PageCollection : CollectionBase
{
public void Add(Page item)
{
InnerList.Add(item);
}
public void Remove(int index)
{
InnerList.RemoveAt(index);
}
public void Remove(Page item)
{
InnerList.Remove(item);
}
public Page this[int index]
{
get
{
return (Page)InnerList[index];
}
set
{
InnerList[index] = value;
}
}
}
【问题讨论】:
标签: c# asp.net collections