先定義強型別集合 CustomerList,再轉換為泛型 List<T>。
// 強型別版本
public class CustomerList : CollectionBase
{
public Customer this[int index]
{
get { return (Customer)List[index]; }
set { List[index] = value; }
}
public int Add(Customer value) { return List.Add(value); }
}
宣告型別參數 T:
public class List<T> : CollectionBase { }
若有私有欄位 private int foo;,轉為 private T foo;,實例化時隨 T 具體化。