Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Compiler Error CS1625 

Error Message

Cannot yield in the body of a finally clause

A yield statement is not allowed in the body of a finally clause. To avoid this error, move the yield statement out of the finally clause.

The following sample generates CS1625:

// CS1625.cs
using System.Collections;

class C : IEnumerable
{
   public IEnumerator GetEnumerator()
   {
      try
      {
      }
      finally
      {
        yield return this;  // CS1625
      }
   }
}

public class CMain
{
   public static void Main() { }
}

Community Additions

ADD
Show:
© 2015 Microsoft