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