zoukankan      html  css  js  c++  java
  • C#索引器1 数字作为索引号

        5.索引器   数字作为索引号    

    public class IndexerClass   

    {        

            private string[] name = new string[2];

            public string this[int index]       

           {            

                 get            

                {               

                     if (index < 2)          

                    {               

                           return name[index];          

                     }               

                    return null;         

                }            

                set           

               {             

                    if (index < 2)         

                    {                

                           name[index] = value;           

                    }            

               }       

          }  

    }

    public class Test

    {       

          public static void Main(string[] args)   

          {           

                 IndexerClass ic = new IndexerClass();         

                 ic[0] = "sssssss";          

                ic[1] = "bbbbbbb";         

                 Console.WriteLine("ic[{0}] 为 {1}",0,ic[0]);      

                 Console.WriteLine("ic[{0}] 为 {1}",1,ic[1]);

                 Console.ReadKey();      

           }   

    }

  • 相关阅读:
    [洛谷P4585] [FJOI2015] 火星商店问题
    [bzoj4311] 向量
    [bzoj4977] [Lydsy1708月赛] 跳伞求生
    sdut-1153 C语言实验——求两个整数之中较大者
    sdut_1116
    sdut_1189
    汉诺塔
    二分查找
    类似二分查找算法
    [YTU]_2922(Shape系列-8)
  • 原文地址:https://www.cnblogs.com/gyc19920704/p/5253348.html
Copyright © 2011-2022 走看看