C# Error
CS1624 – The body of ‘{0}’ cannot be an iterator block because ‘{1}’ is not an iterator interface type
Reason for the Error & Solution
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: , , , . 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;
}
}
}