zoukankan      html  css  js  c++  java
  • 索引

     1     class Program
     2     {
     3 
     4         static void Main()
     5         {
     6             var pair = new Pair<int>(10,12);
     7 
     8             Console.WriteLine($"this is {pair.First} and {pair[PairItem.Second]} other {pair[0]}");
     9             Console.ReadKey();
    10         }
    11     }
    12 
    13     interface IPair<T>
    14     {
    15         T First { get; }
    16         T Second { get; }
    17         T this[PairItem index] { get; }
    18     }
    19 
    20     internal enum PairItem
    21     {
    22         First,
    23         Second
    24     }
    25 
    26     internal struct Pair<T> : IPair<T>
    27     {
    28         public Pair(T first,T second)
    29         {
    30             First = first;
    31             Second = second;
    32         }
    33 
    34         public T this[PairItem index]
    35         {
    36             get
    37             {
    38                 switch (index)
    39                 {
    40                     case PairItem.First:
    41                         return First;
    42                     case PairItem.Second:
    43                         return Second;
    44                     default:
    45                         throw new NotImplementedException();
    46                 }
    47             }
    48             set
    49             {
    50                 switch (index)
    51                 {
    52                     case PairItem.First:
    53                         First = value;
    54                         break;
    55                     case PairItem.Second:
    56                         Second = value;
    57                         break;
    58                     default:
    59                         throw new NotImplementedException();
    60                 }
    61             }
    62         }
    63 
    64         public T First{ get; private set; }
    65 
    66         public T Second { get; private set; }
    67     }
    View Code

    重点在于这个

  • 相关阅读:
    蓝桥杯程序设计 剪格子
    sql中 1<> 1=1的用处
    form表单的6种提交方式
    js中添加监听,判断是什么事件
    angular iFrame加载资源问题
    报表往子报表里传入list
    struts 文件上传
    获取运行时的泛型类型
    Dao层抽取BaseDao
    SSH整合总结
  • 原文地址:https://www.cnblogs.com/bhfdz/p/8985103.html
Copyright © 2011-2022 走看看