C# 泛型

泛型:泛型的作用可以将类和方法将一个或多个类型的指定推迟到客户端代码声明并实例化的时候。可以最大限度地重用代码、包含类型的安   

    全以及提高性能。


// Declare the generic class.
public class GenericList<T>
{
    void Add(T input) { }
}
class TestGenericList
{
    private class ExampleClass { }
    static void Main()
    {
        // Declare a list of type int.
        GenericList<int> list1 = new GenericList<int>();

        // Declare a list of type string.
        GenericList<string> list2 = new GenericList<string>();

        // Declare a list of type ExampleClass.
        GenericList<ExampleClass> list3 = new GenericList<ExampleClass>();
    }
}

posted @ 2012-11-05 16:20  杨斌_济南  阅读(198)  评论(0编辑  收藏  举报