zoukankan      html  css  js  c++  java
  • C# 类内部添加索引器

        public class PersonTable : Indexer
        {
            public int xuhao { get; set; }
            public string name { get; set; }
            public string tel { get; set; }
    
            string Indexer.this[int index]
            {
                get
                {
                    if (index == 0) return xuhao.ToString();
                    else if (index == 1) return name;
                    else if (index == 2) return tel;
                    else return null;
                }
                set
                {
                    if (index == 0) xuhao = Convert.ToInt32(value);
                    else if (index == 1) name = value;
                    else if (index == 2) tel = value;
                }
            }
    
            int Indexer.this[string propname]
            {
                get
                {
                    if (propname == "xuhao") return 0;
                    else if (propname == "name") return 1;
                    else if (propname == "tel") return 2;
                    else return -1;
                }
            }
        }
        public interface Indexer
        {
            //定义索引器
            string this[int index] { get; set; }
            //获取索引,传入值必须为tolower
            int this[string propname] { get; }
        }
  • 相关阅读:
    java内存溢出
    jstack命令使用
    JVM问题排查步骤
    c++指针常量和常量指针
    c++ 通讯录
    冒泡排序
    翻转数组
    敲桌子
    求一个100-999之间的水仙花数
    elasticsearch 模板的使用
  • 原文地址:https://www.cnblogs.com/GoCircle/p/7761013.html
Copyright © 2011-2022 走看看