zoukankan      html  css  js  c++  java
  • 索引器

     1 class SampleCollection<T>
     2 {
     3     private T[] arr = new T[100];
     4     public T this[int i]
     5     {
     6         get
     7         {
     8             return arr[i];
     9         }
    10         set
    11         {
    12             arr[i] = value;
    13         }
    14     }
    15 }
    16 
    17 // This class shows how client code uses the indexer
    18 class Program
    19 {
    20     static void Main(string[] args)
    21     {
    22         SampleCollection<string> stringCollection = new SampleCollection<string>();
    23         stringCollection[0] = "Hello, World";
    24         System.Console.WriteLine(stringCollection[0]);
    25     }
    26 }
    View Code
  • 相关阅读:
    bzoj1027
    bzoj1069
    poj2079
    poj2187
    bzoj2281
    bzoj2285
    bzoj1558
    bzoj1822
    bzoj1559
    bzoj1570
  • 原文地址:https://www.cnblogs.com/Jonish/p/3270523.html
Copyright © 2011-2022 走看看