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

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...