//原来写法 Public class Stack { object[] m_Items; public void Push(object item) {...} public object Pop() {...} } Stack stack = new Stack(); stack.Push(1); int number = (int)stack.Pop();
//有了泛型后 Public class Stack T { T[] m_Items; public void Push(T item) {...} public T Pop() {...} } Stack int stack = new Stack int (); stack.Push(1); int number = (int)stack.Pop();
在文件头部使用using 为特定类型取别名,别名作用范围是整个文件 例子 using List = LinkedList int,string ; class ListClient { static void Main(string[] args) { List list = new List(); list.AddHead(123, AAA ); } }