zoukankan      html  css  js  c++  java
  • 泛型和泛型集合

     泛型:通过参数化类型来实现在同一份代码上操作多种数据类型。利用“参数化类型”将类型抽象化,从而实现灵活的复用。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class fanxing : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int obj = 2;
            Test<int> test = new Test<int>(obj);
            Label1.Text = "int:" + test.obj;
            string obj2 = "hello world";
            Test<string> test1 = new Test<string>(obj2);
            Label2.Text = "String:" + test1.obj;
        }
    
        class Test<T>           //1、  Test是一个泛型类。T是要实例化的范型类型。如果T被实例化为int型,那么成员变量obj就是int型的,如果T被实例化为string型,那么obj就是string类型的。                   
        {
            public T obj;
            public Test(T obj)
            {
                this.obj = obj;
            }
        }
    }
    

      

  • 相关阅读:
    Linux
    python中元类
    POJ 1182 食物链
    POJ 1733 Parity game
    top 介绍
    周记 2014.8.31
    windows10配置python
    oracle执行update时卡死问题的解决办法
    An Easy Introduction to CUDA C and C++
    super()
  • 原文地址:https://www.cnblogs.com/May-day/p/5630094.html
Copyright © 2011-2022 走看看