今天学习了泛型,有如何定义泛型,如何使用泛型。
定义一人泛型方法,如实现数据的交换
public void Swap<T>(ref T a, ref T b)
{
T temp;
temp = a;
a = b;
b = temp;
}
定义一个泛型类
public class 类名<T>
{
定义的变量及属性;
}
非泛型列表:
Array
ArrayList
Hashtable
SortedList
Queue
Stack
泛型列表:
List<T>
Dictionary<TKey,TValue>
Queue<T>
Stack<T