if i have a class that contains a hashtable, is it possible to modify the class to access the hashtable members directly (eg. classname["value"]) instead of classname.hashtable["value"]?
Printable View
if i have a class that contains a hashtable, is it possible to modify the class to access the hashtable members directly (eg. classname["value"]) instead of classname.hashtable["value"]?
I don't really see the point but something like this will work for reading value you can add the set yourself.
Code:class MainClass
{
private Hashtable tbl = new Hashtable();
public MainClass()
{
tbl.Add("one","number one");
}
public object this[object key]
{
get{return tbl[key];}
}
public static void Main(string[] args)
{
MainClass cls = new MainClass();
Console.WriteLine(cls["one"].ToString());
}
}
thanks for the help... will try it tomorrow when i get time.
FYI, i am creating a general class that stores application preferences so i thought this would be a good thing to implement for it. otherwise i would have to create individual properties for accessing each preference.