C# Error CS1624 – The body of ‘{0}’ cannot be an iterator block because ‘{1}’ is not an iterator interface type

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;  
        }  
    }  
}  

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...