HomeCSharpC# 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

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

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