.NET 4.x Реализация IEnumerator и IEnumerator - C#
Формулировка задачи:
Для новой коллекции пишу интерфейсы. Я так понял, что реализуется обычно и обычный и обобщенный варианты. Пишу:
Получаю ошибку
"ConsoleApplication1.A" не реализует член интерфейса "ConsoleApplication1.IEnumerator.Current". "ConsoleApplication1.A.Current" не может реализовать "ConsoleApplication1.IEnumerator.Current", потому что не имеет соответствующего возвращаемого типа "object".
public interface IEnumerator
{
bool MoveNext();
object Current { get; }
void Reset();
}
public interface IEnumerable
{
IEnumerator GetEnumerator();
}
public interface IEnumerator<T>:IEnumerator,IDisposable
{
new T Current {get;}
}
public interface IEnumerable<T> : IEnumerable
{
IEnumerator<T> GetEnumerator();
}
public class A:IEnumerator<int>
{
public int Current
{
get { return 1; }
}
} Решение задачи: «.NET 4.x Реализация IEnumerator и IEnumerator»
textual
Листинг программы
public class A:IEnumerator<int>
{
object IEnumerator.Current
{
get { return Current; }
}
public int Current
{
get { return 1; }
}
}