终于有时间静心 看点基础的东西
看了陈广老师的索引器
class IndexClass
{
private Hashtable name=new Hashtable();
public string this[int index]//A 索引器
{
get{ return name[index].Tostring();}
set{ name.Add(index,value);}
}
public int this[string aName]//B索引器
{
get
{
foreach(DictionaryEntry d in name)
{
if(d.Value.ToString()==aName)
{
return Convert.ToInt32(d.Key);
}
return -1;
}
set{name.Add(value,aName);}
}
}
}
}
class test
{
static void main()
{
IndexClass b=new IndexCLass();
b[100]="张三";
Console.WriteLine("编号为100的员工是:"+b[100]);
//调用B索引器
Console.WriteLine("张三的编号是:"+b["张三"]);
b["马六"]=400;
//调用A
Console.WriteLine("编号为400的员工是:"+b[400]);
}
}