Casting Enumerator?!?

This is a discussion on Casting Enumerator?!? within the C# Programming forums, part of the General Programming Boards category; I have implemented a Properties class that may contain name-value pairs. They are stored in a Hashtable. Now I want ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    41

    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>?

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

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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.
    MagosX.com

    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, 12:09 PM
  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, 01:17 AM
  4. Type casting
    By Lionmane in forum C Programming
    Replies: 28
    Last Post: 08-20-2005, 03:16 PM
  5. question about casting pointers/other types also??
    By newbie02 in forum C++ Programming
    Replies: 3
    Last Post: 08-07-2003, 06:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21