Results 1 to 3 of 3

Thread: [RESOLVED] question about classes

  1. #1

    Thread Starter
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Resolved [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"]?
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196

    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());
    		}
    		
    		
    	}

  3. #3

    Thread Starter
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    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.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width