zoukankan      html  css  js  c++  java
  • c#基础知识索引器

    代码
    class SampleCollection<T>
    {
        
    private T[] arr = new T[100];
        
    public T this[int
     i]
        {
            
    get

            {
                
    return arr[i];
            }
            
    set

            {
                arr[i] 
    = value;
            }
        }
    }

    // This class shows how client code uses the indexer

    class Program
    {
        
    static void Main(string
    [] args)
        {
            SampleCollection
    <string> stringCollection = new SampleCollection<string>
    ();
            stringCollection[
    0= "Hello, World"
    ;
            System.Console.WriteLine(stringCollection[
    0
    ]);
        }
    }

     在这里我们看到,无非是实现了一个泛型算法

           等同于 Ontology

            List<string> lit=new List<string>();

                               lis.add("lee");

                                                                         一般我们用 string lee{ get;set;}

     是用来访问一个对象的里面的属性,他这里相对于把对象自身当作一个属性来访问,这样以来就形成了一个新的访问形式,当然有很多方式可以替换。

  • 相关阅读:
    0401. Binary Watch (E)
    0436. Find Right Interval (M)
    0151. Reverse Words in a String (M)
    1344. Angle Between Hands of a Clock (M)
    0435. Non-overlapping Intervals (M)
    0434. Number of Segments in a String (E)
    0063. Unique Paths II (M)
    0062. Unique Paths (M)
    0100. Same Tree (E)
    0190. Reverse Bits (E)
  • 原文地址:https://www.cnblogs.com/joke168/p/4122726.html
Copyright © 2011-2022 走看看