|
-
Jul 30th, 2005, 05:31 AM
#1
[RESOLVED] question about classes
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"]?
-
Jul 30th, 2005, 07:06 AM
#2
Re: question about classes
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());
}
}
-
Jul 30th, 2005, 07:20 AM
#3
Re: question about classes
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|