Thread: Casting Enumerator?!?

  1. #1
    Registered User
    Join Date
    Nov 2005

    Thumbs up Casting Enumerator?!?

    I have implemented a Properties class that may contain name-value pairs. They are stored in a Hashtable. Now I want to implement this function:
    Enumerator<string> PropertyNames();

    How do I do that? When I do GetEnumerator on the Hashtable inside the Properties class, I get a Enumerator<Hashtable.Keys> back. How do I return Enumerator<string>?

    namespace qwerty 
    Class Properties
    private   Hashtable mHashtable = new Hashtable();
    public    Enumerator<string>  PropertyNames()
    public AddProp(string Name, string Value)
       mHashtable.Add(Name, Value); 

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Make your own enumerator class (which implements System.Collections.IEnumerator) which is returned from the properties class. It should have 3 methods: Reset, MoveNext and Current.get. To allow your properties class to be used directly in an foreach statement make sure it implements System.Collections.IEnumerable.

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advantages of c++ type casting over c type casting
    By kaibalya2008 in forum C++ Programming
    Replies: 10
    Last Post: 05-05-2009, 11:09 AM
  2. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  3. casting the system exstracted date into seperate ints
    By bazzano in forum C Programming
    Replies: 1
    Last Post: 08-30-2005, 12:17 AM
  4. Type casting
    By Lionmane in forum C Programming
    Replies: 28
    Last Post: 08-20-2005, 02:16 PM
  5. question about casting pointers/other types also??
    By newbie02 in forum C++ Programming
    Replies: 3
    Last Post: 08-07-2003, 05:01 AM