This topic has not yet been rated - Rate this topic

Compiler Error CS1624 

Error Message

The body of 'accessor' cannot be an iterator block because 'type' is not an iterator interface type

This error occurs if an iterator accessor is used but the return type is not one of the iterator interface types: IEnumerable, IEnumerable, IEnumerator, IEnumerator. To avoid this error, use one of the iterator interface types as a return type.

Example

The following sample generates CS1624:

// CS1624.cs
using System;
using System.Collections;

class C
{
    public int Iterator
    // Try this instead:
    // public IEnumerable Iterator
    {
        get  // CS1624
        {
            yield return 1;
        }
    }
}
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ