• 泛型


    泛型约束小计:

     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

  • 相关阅读:
    SQL2008性能计数器注册表配置单元一致性失败
    win8 下 IIS APPPOOLDefaultAppPool 登录失败的解决方法
    Win8 x64环境下VS2010 C#工程运行报错:没有注册类 (异常来自 HRESULT:0x80040154
    编辑距离
    UVA 147 Dp(完全背包)
    poj 1141 Brackets Sequence
    hdu2612 Find a way BFS
    I
    javascript--运算符
    javascript--变量
  • 原文地址:https://www.cnblogs.com/bhfdz/p/8952707.html
Copyright © 2020-2023  润新知