foreach、using。public class Stack
{
private object[] items = new object[100];
public void Push(object data) { ... }
public object Pop() { ... }
}
Stack s = new Stack();
s.Push(new Customer());
Customer c = (Customer)s.Pop(); // 需轉型
InvalidCastException。泛型將在保持語法簡潔的前提下,解決上述問題。