Example #1
0
        /// <summary>
        /// 把一个索引器写成属性的形式取值和赋值
        /// </summary>
        public static void Exec1()
        {
            Indexer2 index2 = new Indexer2();

            index2["aaa"] = "aa";
            index2["bbb"] = "bb";

            dynamic myObj = new DynamicIndexer(index2);

            myObj.ccc = "cc";
            Console.WriteLine(myObj.ccc);
            string value = myObj.aaa;

            Console.WriteLine(myObj.aaa);
        }
Example #2
0
        public void Test()
        {
            Indexer1 index1 = new Indexer1();

            index1[0] = "aaa";

            Indexer2 index2 = new Indexer2();

            index2["aaa"] = "aaa";

            Indexer3 index3 = new Indexer3();

            index3["aaa"] = 1;
            string value = index3[1];

            Indexer4 index4 = new Indexer4();

            index4["zhangshuai", "001"] = "22";
            string age = index4["zhangshuai", "001"];
        }
Example #3
0
 Indexer2 index2 = new Indexer2();//要求类中必须索引器
 public DynamicIndexer(Indexer2 index2)
 {
     this.index2 = index2;
 }