A
Andrus
Code below causes error in class definition line
.....Isolator<T>' does not implement interface member
'System.Collections.IEnumerable.GetEnumerator()'.
'Myapp.Isolator<T>.GetEnumerator()' cannot implement
'System.Collections.IEnumerable.GetEnumerator()' because it does not have
the matching return type of 'System.Collections.IEnumerator'.
I tried to change method signature to
public IEnumerator GetEnumerator()
bu this causes another error
....Isolator<T>' does not implement interface member
'System.Collections.Generic.IEnumerable<T>.GetEnumerator()'.
'Myapp.Isolator<T>.GetEnumerator()' cannot implement
'System.Collections.Generic.IEnumerable<T>.GetEnumerator()' because it does
not have the matching return type of
'System.Collections.Generic.IEnumerator<T>'.
How to make this code work ?
Andrus.
using System;
using System.Collections;
using System.Collections.Generic ;
public class Isolator<T> : IEnumerable<T>
{
IEnumerable<T> inner;
public Isolator(IEnumerable<T> enumerable)
{
inner = enumerable;
}
public IEnumerator<T> GetEnumerator()
{
ArrayList<T> list = new ArrayList<T>();
foreach (object o in inner)
list.Add(o);
return list.GetEnumerator();
}
}
.....Isolator<T>' does not implement interface member
'System.Collections.IEnumerable.GetEnumerator()'.
'Myapp.Isolator<T>.GetEnumerator()' cannot implement
'System.Collections.IEnumerable.GetEnumerator()' because it does not have
the matching return type of 'System.Collections.IEnumerator'.
I tried to change method signature to
public IEnumerator GetEnumerator()
bu this causes another error
....Isolator<T>' does not implement interface member
'System.Collections.Generic.IEnumerable<T>.GetEnumerator()'.
'Myapp.Isolator<T>.GetEnumerator()' cannot implement
'System.Collections.Generic.IEnumerable<T>.GetEnumerator()' because it does
not have the matching return type of
'System.Collections.Generic.IEnumerator<T>'.
How to make this code work ?
Andrus.
using System;
using System.Collections;
using System.Collections.Generic ;
public class Isolator<T> : IEnumerable<T>
{
IEnumerable<T> inner;
public Isolator(IEnumerable<T> enumerable)
{
inner = enumerable;
}
public IEnumerator<T> GetEnumerator()
{
ArrayList<T> list = new ArrayList<T>();
foreach (object o in inner)
list.Add(o);
return list.GetEnumerator();
}
}