• 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();      

           }   

    }

  • 相关阅读:
    JavaSE之流程控制结构
    JavaSE的基本语法
    排序算法
    Java实现归并排序
    Java中线程池的介绍
    Java锁的升降级及synchoronized优化
    ThreadLocal应用与原理
    spring bean 实例化bean前后进行相应的设置
    maven依赖配置和依赖范围
    springmvc校验
  • 原文地址:https://www.cnblogs.com/gyc19920704/p/5253348.html
Copyright © 2020-2023  润新知