I have the following problem:
I have a list and add string items to this list.
Then I create an Enumerator out of the list. When I loop through the list with the MoveNext()
command it works when I access the enumerator directly. When I use the Enumerator properties to access the enumerator it doesn't work. The MoveNext()
command doesn't increment the index.
Here is the code I used. Thanks a lot for your help.
public class DummyKlasse
{
public List<string>.Enumerator enumerator;
public List<string> list;
public DummyKlasse()
{
Console.WriteLine("Test");
list = new List<string>();
enumerator = new List<string>.Enumerator();
}
public List<string>.Enumerator Enumerator
{
get { return enumerator; }
set { enumerator = value;}
}
public List<string> List
{
get { return list; }
set { list = new List<string>(value); }
}
public void dummyfunction()
{
List.Add("test1");
List.Add("test2");
enumerator = List.GetEnumerator();
}
}
public class Program
{
static void Main(string[] args)
{
DummyKlasse dummyklasse = new DummyKlasse();
dummyklasse.dummyfunction();
//Does not work with properties
/*
while (dummyklasse.Enumerator.MoveNext())
{
Console.WriteLine(dummyklasse.Enumerator.Current);
}
*/
//Works WITHOUT properties
while (dummyklasse.enumerator.MoveNext())
{
Console.WriteLine(dummyklasse.enumerator.Current);
}
Console.ReadLine();
}
}