I have some code I always use to make collections of my object. This code and be used like 10 times in some of my project with the object replaced.
Is there any way I can create this as a function that can take whatever object? I’ve heard of <T> but I am unsure how to use it in this.
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;
}
}
}
Just use
List<T>object to create strongly typed collection of your objects. In your example use justAlso check
System.Collections.Genericnamespace for strongly typed (generic) collections.