Export (0) Print
Expand All
Expand Minimize

Compiler Error CS1688

Cannot convert anonymous method block without a parameter list to delegate type 'delegate' because it has one or more out parameters

The compiler allows parameters to be omitted from an anonymous method block in most cases. This error arises when the anonymous method block does not have a parameter list, but the delegate has an out parameter. The compiler does not allow this situation because it would need to ignore the presence of the out parameter, which is unlikely to be the correct behavior.

The following code generates error CS1688.

// CS1688.cs
using System;
delegate void OutParam(out int i);
class ErrorCS1676
{
    static void Main() 
    {
        OutParam o;
        o = delegate  // CS1688
        // Try this instead:
        // o = delegate(out int i)
        { 
            Console.WriteLine("");
        };
    }
}

Community Additions

ADD
Show:
© 2014 Microsoft