C# Error CS1688 – Cannot convert anonymous method block without a parameter list to delegate type ‘{0}’ because it has one or more out parameters

C# Error

CS1688 – Cannot convert anonymous method block without a parameter list to delegate type ‘{0}’ because it has one or more out parameters

Reason for the Error & Solution

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.

Example

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("");  
        };  
    }  
}  

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...