zoukankan      html  css  js  c++  java
  • 泛型

    泛型约束小计:

     1 class Program
     2     {
     3         static void Main(string[] args)
     4         {
     5             {
     6                 var generice = new GenericClass();
     7            
     8                 generice.ShowInt(11);
     9                 generice.ShowDateTime(DateTime.Now);
    10                 generice.ShowPeople(new People {Id = 11, Name = "Tom"});
    11             }
    12 
    13             {
    14                 Console.WriteLine("---------------------------------------");
    15                 var generice = new GenericClass2();
    16                 generice.ShowObj(11);
    17                 generice.ShowObj(DateTime.Now);
    18                 generice.ShowObj(new People {Id = 11, Name = "Tom"});
    19             }
    20 
    21             {
    22                 Console.WriteLine("---------------------------------------");
    23                 var generice = new GenericClass3();
    24                 generice.ShowT<int>(11);
    25                 generice.ShowT<DateTime>(DateTime.Now);
    26                 generice.ShowT<People>(new People { Id = 11, Name = "Tom" });
    27             }
    28 
    29             Console.ReadKey();
    30         }
    31     }
    32     public class GenericClass3
    33     {
    34         public void ShowT<T>(T t)
    35         {
    36             Console.WriteLine("ShowT print {0},ShowT Parament Type Is {1}", t, t.GetType());
    37         }
    38     }
    39 
    40     public class GenericClass2
    41     {
    42         public void ShowObj(object obj)
    43         {
    44             Console.WriteLine("ShowObj print {0},ShowObj Parament Type Is {1}", obj, obj.GetType());
    45         }
    46     }
    47 
    48     public class GenericClass
    49     {
    50         public void ShowInt(int n)
    51         {
    52             Console.WriteLine("ShowInt print {0},ShowInt Parament Type Is {1}", n, n.GetType());
    53         }
    54         public void ShowDateTime(DateTime dt)
    55         {
    56             Console.WriteLine("ShowDateTime print {0},ShowDateTime Parament Type Is {1}", dt, dt.GetType());
    57         }
    58         public void ShowPeople(People people)
    59         {
    60             Console.WriteLine("ShowPeople print {0},ShowPeople Parament Type Is {1}", people, people.GetType());
    61         }
    62     }
    63 
    64     public class People
    65     {
    66         public int Id { get; internal set; }
    67         public string Name { get; internal set; }
    68     }
    View Code

  • 相关阅读:
    集合的遍历和扩容原理
    最新鲜最详细的Android SDK下载安装及配置教程
    开启IIS Express可以调试X64项目
    C# 正则表达式大全
    Windows下SQLMAP的安装图解
    当前比较流行的前端框架2
    前端组件库1
    服务器Windows 登录 出现401 错误
    IPV6配置
    implicit和 explicit关键字
  • 原文地址:https://www.cnblogs.com/bhfdz/p/8952707.html
Copyright © 2011-2022 走看看