C#索引器2 字符串作为索引号
6.索引器 字符串作为索引号
public class Demo
{
private Hashtable name = new Hashtable();
public string this[string index]
{
set
{
name.Add(index, value);
}
get
{
return name[index].ToString();
}
}
}
public class Test
{
public static void Main(string[] args)
{
Demo dd = new Demo();
dd["A"] = "SB";
dd["B"] = "EB";
Console.WriteLine(dd["A"]);
Console.WriteLine(dd["B"]);
//Console.WriteLine(dd["C"]);
Console.ReadKey();
}
}