Search code examples
c#iteratorwritable

Is there a C# equivalent to the STL output iterator?


I'm looking for some type of iterator/enumerator that can write to the backing collection. As I understand it c# enumerators are read-only.


Solution

  • There's nothing already existing in C# to do such a thing.

    You're right IEnumerator's Current property is defined as a getter only.

    You'd need to write a new class and/or interface to support such a thing.

    interface IOutputable<T> {
      IOutputer<T> GetOutputer();
      }
    
    interface IOutputer<T> {
    
      T Current { set; }
    
      bool MoveNext();
      void Reset();
      }