zoukankan      html  css  js  c++  java
  • C# 泛型

    2.0 版 C# 语言和公共语言运行时 (CLR) 中增加了泛型。泛型将类型参数的概念引入 .NET Framework,类型参数使得设计如下类和方法成为可能:这些类和方法将一个或多个类型的指定推迟到客户端代码声明并实例化该类或方法的时候。例如,通过使用泛型类型参数 T,您可以编写其他客户端代码能够使用的单个类,而不致引入运行时强制转换或装箱操作的成本或风险,如下所示:

    // 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>();
        }
    }
    

      

    Stay hungry, stay foolish
  • 相关阅读:
    JDBC的简单笔记
    javascript学习笔记二
    javascript学习一、js的初步了解
    css的简单学习笔记
    c++ 拷贝构造函数
    C++ new delete
    c++ 析构函数
    c++成员初始化和构造函数
    C++ 类和对象浅解
    c++ constexpr
  • 原文地址:https://www.cnblogs.com/xiao-hei/p/3858226.html
Copyright © 2011-2022 走看看