zoukankan      html  css  js  c++  java
  • C#: the sample usage of c# template

    1. class definition with constraints

    1 class Test<T, V> where V:MyType {
    2         public String name;
    3         public T value;
    4         public virtual void print() {
    5             Console.WriteLine("{0}={1}", name, value);
    6         }//print()
    7     } //class

    2. inherited class definition with constraint( my use constraint)

    1     
    2     class Test2<T1,T2>  : Test<T1,T2>  where T2:MyType{
    3         public override void print() {
    4             Console.WriteLine("IN Test2");
    5             base.print();
    6         }//print()
    7         
    8     }

    3. template in method(static and non-static)

    1         public static void testme<T>(T val) where T:IHoho, IOK{
    2             Console.WriteLine(val);
    3         }
    4         public void testme2<T>(T val) {
    5             Console.WriteLine(val);
    6         }

    4. Usage

     1         public static void Main(string[] args)
     2         {
     3             Test<int, MyType2> intValue = new Test<int, MyType2>();
     4             intValue.name = "int";
     5             intValue.value = 100;
     6             intValue.print();
     7             Test2<float, MyType2> floatValue = new Test2<float, MyType2>();
     8             floatValue.name = "float";
     9             floatValue.value = 200.10F;
    10             floatValue.print();
    11             testme(new MyType2(100));
    12             testme(new MyType2("Hello"));
    13             new Program().testme2("World");
    14             
    15         }
  • 相关阅读:
    Element Pagination分页组件 二次封装
    vue 发送短信验证码倒计时
    生成动态海报,带二维码
    H5九宫格抽奖,亲测可用
    elementui el-select使用远程搜索单选,输入内容不会触发remote-method
    日期格式转换,转换格式YYYY-MM-DD HH:mm:ss
    bignumber.js是一款用于任意精度十进制和非十进制算术的JavaScript库
    element table切换分页不勾选的自带方法
    密码强度校验
    webdriver-设置代理
  • 原文地址:https://www.cnblogs.com/sliencer/p/2736418.html
Copyright © 2011-2022 走看看