C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-24-2002, 03:50 PM   #1
JBravo
Guest
 
Posts: n/a
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);
            }
        }
    }
}
  Reply With Quote
Old 10-25-2002, 09:41 AM   #2
the hat of redundancy hat
 
nvoigt's Avatar
 
Join Date: Aug 2001
Location: Hannover, Germany
Posts: 2,769
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.
nvoigt is offline   Reply With Quote
Old 10-29-2002, 10:31 AM   #3
JBravo
Guest
 
Posts: n/a
Thanks nvoigt.
That sorts it out.
  Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
foreach and IEnumerator George2 C# Programming 2 04-30-2008 08:01 AM


All times are GMT -6. The time now is 09:44 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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