我有一個類實現IEnumerator<string>
。請看下圖:爲什麼我需要IEnumerator.Current在一個實現IEnumerator <T>的類中?
public class MyClass : IEnumerator<string>
{
public bool MoveNext()
{
//....
}
//Implement other required methods....
//Confusion lies below:
public string Current { get { return this.CurrentLine; } }
//Why do I need to implement IEnumerator.Current?! In my tests, it's not even called during my iteration
object IEnumerator.Current { get { throw new NotImplementedException(); } }
}
除了存在兩個IEnumerator<T>
接口和IEnumerator
接口(其中IEnumerator<T>
繼承)上.Current財產,什麼是實現它的點的事實呢?如上所見,它甚至沒有被稱爲。
+1給出了一個例子,說明如何在這種情況下調用IEnumerator.Current的實現。 – contactmatt 2011-03-02 19:12:47