Export (0) Print
Expand All
Expand Minimize

Compiler Error CS1501

No overload for method 'method' takes 'number' arguments

A call was made to a class method, but there is no form of the method that takes the necessary number of arguments.

CS1501 could occur if you are calling a method on a class in a referenced assembly and if that method has default values on one or more of its parameters. C# does not let you create methods with a default value on a parameter, but another language that targets the runtime might. If a parameter (in a method in a referenced assembly) has a default value, you must still call the method and explicitly pass all parameters.

CS1501 could occur when you allocate memory for a delegate; you must also specify the name of the method that the delegate represents.

The following sample generates CS1501:

// CS1501.cs
public class a
{
   // declare the following constructor to resolve this CS1501
   /*
   public a(int i)
   {
   }
   */

   public static void Main()
   {
      a aa = new a(2);   // CS1501
   }
}

The following sample generates CS1501:

// CS1501a.cs
using System;

delegate string func(int i);   // declare the delegate

class a
{
   static func dt;   // class member-field of the declared delegate type

   public static void Main()
   {
      dt = new func();   // CS1501
      // try the following line instead
      // dt = new func(z);   // this works
      x(dt);
   }

   public static string z(int j)
   {
      Console.WriteLine(j);
      return j.ToString();
   }

   public static void x(func hello)
   {
      hello(8);
   }
}
Show:
© 2015 Microsoft