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

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;}

}

最新文章

  1. JFreeChart
  2. 安装MariaDB和简单配置
  3. Bootstrap~日期控制
  4. smarty访问数组中的数据,如果是关联数组直接用点.
  5. js-JavaScript高级程序设计学习笔记16
  6. weblogic jetty debug 远程
  7. 解决死锁SQL
  8. 【特别推荐】Node.js 入门教程和学习资源汇总
  9. 【转】【UML】使用Visual Studio 2010 Team System中的架构师工具(设计与建模)
  10. MVC&amp;WebForm对照学习:传值方式
  11. 在VC6中使用ogre进行游戏开发
  12. POJ 3384 Feng Shui
  13. 【编程范式】C语言1
  14. 关于ALTERA生成IP核卡住
  15. vim中SnipMate 和 YouCompleteMe 插件触发键 tab 冲突
  16. WordPress禁止版本修订历史、自动保存和自动草稿最新方法汇总
  17. linux rzsz(lrzsz)安装
  18. 解析数学表达式 代码解析AST语法树
  19. LINUX内核PCI扫描过程
  20. 有关wkwebview和UIwebview获取html中的标签方法

热门文章

  1. linux配置IP的方法
  2. c#找不到类型或命名空间名称“Word”
  3. jquery条件选择多个元素(与、或者)
  4. PL/SQL 中查询CLOB字段内容
  5. 第4章 jQuery的事件和动画(1)——事件篇
  6. 捕获EF提交异常
  7. sqlmap注入小结
  8. HBase命令(三) -- 增删改查
  9. C# 协变out 、逆变 in
  10. XStream使用总结