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;
            }
        }
    }
    

      

  • 相关阅读:
    DLL内存加载
    Intel汇编程序设计-高级过程(上)
    Intel汇编程序设计-高级过程(上)
    C#-常用
    C#-常用
    C#-MD5
    C#-MD5
    C#-文件操作
    POJ 3320 Jessica's Reading Problem
    POJ 2456 Aggressive cows
  • 原文地址:https://www.cnblogs.com/May-day/p/5630094.html
Copyright © 2011-2022 走看看