zoukankan      html  css  js  c++  java
  • C# 属性和索引

    //用索引取一个记录中的各项

    using system;

    class IndexerRecord{

    private string[] data= new string [6];

    private string[] keys = {

         "Author""Publisher""Title",

          "Subject""ISBN""Comments" 

           };

    //程序中用了两种方法索引,一是整数作下标,一是关键字(字符串)作下标

    public string this [int idx]{

         set

        {

            if( idx>=0 && idx<data.length )

                data[idx]=value;

       }

       get

      {

         if(idx>=0 && idx <data.length)

           return data[idx];

         return NULL;

      }

    }

     public string this[string key]

    {

        set

        {

           ind idx = FindKey(key);

           this[idx] = value;

        }

       get

       {

          return this[FindKey(key)];

       }

    }

      private int FindKey(string key)

    {

          for(int i=0;i<keys.length;i++)

             if(keys[i] == key)return i;

         return -1;

     }

     static void Main()

    {

         IndexRecord record = new IndexRecord();

         record[0] = "马克 吐温";

         record[1] = "Crox出版公司";

         record[2] = "汤姆 索亚历险记";

         Console.WriteLine(record["Title"]);

         Console.WriteLine( record[ "Author" ] );

         Console.WriteLine( record[ "Publisher" ] );

    }

    }

    //属性

    class Person

    {

       public string Name{set;get;}

    }

  • 相关阅读:
    curl上传图片文件
    手工制作简单后台模板
    首页自动生成静态化html
    svn-多个项目版本库和自动同步更新post-commit
    Snoopy+phpquery采集demo
    phpstorm使用手册
    mac系统使用帮助
    upupw一键绿色免安装环境包
    去掉文件夹的.svn文件
    centos安装svn服务器
  • 原文地址:https://www.cnblogs.com/573177885qq/p/4229774.html
Copyright © 2011-2022 走看看