![]() |
| | #1 |
| Guest
Posts: n/a
| 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 |
| the hat of redundancy hat 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 | |
| | #3 |
| Guest
Posts: n/a
| Thanks nvoigt. That sorts it out. |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| foreach and IEnumerator | George2 | C# Programming | 2 | 04-30-2008 08:01 AM |