user14378837
user14378837

Reputation:

No overload matches the delegate c#

No overload for "GetSum" matches the delegate Formula<double>

How can i fix this error?

my delegate is:

public delegate T Formula <T>(T arg1); 

Getsum:

    public delegate T Formula <T>(T arg1);

    class CalculatorClass
    {
        public static double total;
        public Formula<double> formula;
        public static double GetSum(double num1, double num2)
        {
            return total = num1 + num2;
        }
}

My code:

      private void btnEqual_Click(object sender, EventArgs e)
            {
                num1 = Convert.ToDouble(txtBoxInput1.Text);
                num2 = Convert.ToDouble(txtBoxInput2.Text);
    
                Formula<double> sum = new Formula<double>(CalculatorClass.GetSum);
    
    
            }

Upvotes: 0

Views: 102

Answers (1)

&#246;mer hayyam
&#246;mer hayyam

Reputation: 199

Your delegate expects one parameter of type T GetSum has obviously 2 parameters. Try changing your delegate to:

public delegate T Formula <T>(T arg1, T arg2);

and it will compile. BTW, you can use built-in delegate Func<in T1,in T2 out TResult> as Func<double, double, double>

Upvotes: 1

Related Questions