HomeCSharpC# Error CS0123 – No overload for ‘method’ matches delegate ‘delegate’

C# Error CS0123 – No overload for ‘method’ matches delegate ‘delegate’

C# Compiler Error

CS0123 – No overload for ‘method’ matches delegate ‘delegate’

Reason for the Error

This C# error will occur when you try to create a delegate in C# with in-correct signature.

For example, try compiling the below code snippet.

namespace DeveloperPublishNamespace
{
    delegate void Delegate1();

    public class DeveloperPublish
    {
        public static void function1(int i) { }
        public static void Main()
        {
            // Error because function1 takes an integer parameter while the delegate Delegate1 doesnot
            Delegate1 d = new Delegate1(function1);  
        }
    }
}

We have declared a delegate without a parameter and when we create an instance by passing a function with a different signature, you will see the below error.

Error CS0123 No overload for ‘function1’ matches delegate ‘Delegate1’ ConsoleApp1 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp1\Program.cs 11 Active

C# Error CS0123 – No overload for 'method' matches delegate 'delegate'

If you are on .NET Mono, the error might look something like this

error CS0123: A method or delegate DeveloperPublishNamespace.DeveloperPublish.function1(int)' parameters do not match delegateDeveloperPublishNamespace.Delegate1()’ parameters

Solution

You can avoid this error by changing the access modifier of the Method to allow its access (if needed).

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