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

           }   

    }

  • 相关阅读:
    21.Merge Two Sorted Lists 、23. Merge k Sorted Lists
    34. Find First and Last Position of Element in Sorted Array
    leetcode 20. Valid Parentheses 、32. Longest Valid Parentheses 、301. Remove Invalid Parentheses
    31. Next Permutation
    17. Letter Combinations of a Phone Number
    android 常见分辨率(mdpi、hdpi 、xhdpi、xxhdpi )及屏幕适配注意事项
    oc 异常处理
    oc 类型判断
    oc Delegate
    oc 协议
  • 原文地址:https://www.cnblogs.com/gyc19920704/p/5253348.html
Copyright © 2011-2022 走看看