IEnumerator

This is a discussion on IEnumerator within the C# Programming forums, part of the General Programming Boards category; Hi All, I'm having a problem with the following code. I get a compiler error //C:\CSharpStuff\ProcessList\ProcessList\Class1.cs(6 4): Cannot implicitly convert ...

  1. #1
    JBravo
    Guest

    Question IEnumerator

    Hi All,
    I'm having a problem with the following code. I get a compiler error
    //C:\CSharpStuff\ProcessList\ProcessList\Class1.cs(6 4): Cannot implicitly convert type 'ProcessListNamespace.structProcessInfo' to 'ProcessListNamespace.ProcessList'
    Does anyone know how to make the class properly emumerable?
    Thanks,
    J

    Code:
    using System;
    using System.Collections;
    
    
    namespace ProcessListNamespace
    {
        public struct structProcessInfo
        {
            public string stringName;
            public string stringProcessID;
            public string stringParentProcessID;
            public string stringUserName;
        }
    
    
    
        class ProcessList 
        {
            private Hashtable ProcessListTable = new Hashtable();
    
            public void AddToList(structProcessInfo ProcessInfo)
            {
                ProcessListTable.Add(ProcessListTable.Count + 1, ProcessInfo);
            }
    
            public void AddToList(string Name, string ProcessID, string PProcessID, string UserName)
            {
                structProcessInfo temp;
                temp.stringName = Name;
                temp.stringParentProcessID = PProcessID;
                temp.stringUserName = UserName;
            }
    
            public void ClearList()
            {
                ProcessListTable.Clear();
            }
    
            public IEnumerator  GetEnumerator()
            {
                return ProcessListTable.GetEnumerator();
            }
    
    
    
    
    
    
    
            static void Main(string[] args)
            {
                structProcessInfo qwe;
    
                qwe.stringName = "Proces4561";
                qwe.stringParentProcessID = "1";
                qwe.stringProcessID = "345";
                qwe.stringUserName = "John";
    
                ProcessList mypl = new ProcessList();
                mypl.AddToList(qwe);
    
                foreach(DictionaryEntry myEntry in mypl)
                {
    Compiler Error-------->    mypl = (structProcessInfo)myEntry.Value;
                    Console.WriteLine("{0} \t {1}", myEntry.Key, qwe.stringName);
                }
            }
        }
    }

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    qwe = (structProcessInfo)myEntry.Value;

    ...is probably what you need. You don't want to assign to your List again, do you ?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    JBravo
    Guest
    Thanks nvoigt.
    That sorts it out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. foreach and IEnumerator
    By George2 in forum C# Programming
    Replies: 2
    Last Post: 04-30-2008, 09:01 AM

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