Share via


Compiler Error CS1629

Unsafe code may not appear in iterators

The C# language specification does not allow unsafe code in iterators.

The following sample generates CS1629:

// CS1629.cs
// compile with: /unsafe  
using System.Collections.Generic;
class C 
{
   IEnumerator<int> IteratorMeth() {
      int i;
      unsafe  // CS1629
      {
         int *p = &i;
         yield return *p;
      }
   }
}