• 索引器


     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace ConsoleApplication1
     8 {
     9     class Program
    10     {
    11         static void Main(string[] args)
    12         {
    13             var myindex = new MyIndex();
    14             myindex[0] = "0";
    15             myindex[1] = "1";
    16             myindex[2] = "2";
    17             myindex[3] = "3";
    18             myindex[4] = "4";
    19             myindex[5] = "5";
    20             myindex[6] = "6";
    21             myindex[7] = "7";
    22             myindex[8] = "8";
    23             myindex[9] = "9";
    24             for (int i = 0; i < 10; i++)
    25             {
    26                 Console.WriteLine(myindex[i]);
    27             }
    28             Console.ReadLine();
    29         }
    30     }
    31     class MyIndex
    32     {
    33         private string[] MyString = new string[10];
    34         public MyIndex()
    35         {
    36             for (int i = 0; i < MyString.Length; i++)
    37             {
    38                 MyString[i] = "N/A";
    39             }
    40         }
    41         public string this[int index]
    42         {
    43             get
    44             {
    45                 string tmp;
    46                 if (index >= 0 && index < MyString.Length)
    47                     tmp = MyString[index];
    48                 else
    49                     tmp = "";
    50                 return tmp;
    51             }
    52             set
    53             {
    54                 if (index >= 0 && index < MyString.Length)
    55                 {
    56                     MyString[index] = value;
    57                 }
    58             }
    59         }
    60     }
    61 }
  • 相关阅读:
    常用网站
    我的第一个 python 爬虫脚本
    在文件夹下所有文件中查找字符串(linux/windows)
    Python 列表 insert() 方法
    mysql 替换 tab 键 ( )
    访问权限的修饰符
    eclipse 快捷键
    位运算
    hadoop 环境搭建
    Hadoop 快速入门
  • 原文地址:https://www.cnblogs.com/handsomer/p/4546574.html
Copyright © 2020-2023  润新知