Error cs1501 no overload for method min takes 1 arguments

Ошибка CS1501 No overload for method takes arguments означает, что метод должен принимать определенное число аргументов, но либо не заданы аргументы в методе, либо идёт попытка вызвать метод без нужных аргументов.

Ошибка CS1501 No overload for method takes arguments означает, что метод должен принимать определенное число аргументов, но либо не заданы аргументы в методе, либо идёт попытка вызвать метод без нужных аргументов.

Рассмотрим два примера, иллюстрирующих обе ситуации:

Ситуация 1. Не задан аргумент в методе:

using System;

public class Program

{

public static void Main()

{

Console.WriteLine(Test1(«abc»));

}

static string Test1(){

return «1»;

}

}

Есть метод Test1 и у него не задан аргумент, поэтому выдается ошибка «Compilation error (line *, col *): No overload for method ‘Test1’ takes 1 arguments».

Ситуация 2

using System;

public class Program

{

public static void Main()

{

Console.WriteLine(Test1());

}

static string Test1(string a){

return a;

}

}

Теперь не забыли задать аргумент в методе, но не указали аргумент при вызове метода Test1, что также приведёт к ошибке «Compilation error (line *, col *): No overload for method ‘Test1’ takes 0 arguments».

А теперь пофиксим ошибку, приведем правильный вариант:

using System;

public class Program

{

public static void Main()

{

Console.WriteLine(Test1(«test»));

}

static string Test1(string a){

return a;

}

}

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
namespace Slide01
{
    class Program
    {
        static void Main()
        {
            System.Console.WriteLine(Min(4, 2, 3));
        }
        
        static int Min(int a, int b, int c)
        {
            return Math.Min(a, Math.Min(b, c));
        }
    }
}

1.Как можно дополнить код, чтобы он начал компилироваться? Выберите все возможные варианты.
а.Дописать «using System.Math;» в начало
б.Написать «System.Math.Min» вместо «Math.Min»
в.Это скомпилируется, но при выполнении метода возникнет ошибка
г.Дописать «using System.Console;» в начало
д.Дописать «using System;» в начало

Controller.cs(9,4,9,15): error CS1501: No overload for method ‘Min’ takes 1 arguments

2. Что это может значить? Отметьте все корректные варианты.
а.Ошибка в файле Controller.cs
б.Ничего страшного, это сообщение можно просто игнорировать
в.Вася привел компилятору всего один аргумент, почему стоит компилировать эту программу. Этого явно мало!
г.Вася попытался вызвать функцию Min с одним аргументом
д.Ошибка в файле Min.cs
е.Вася снова забыл написать using
ж.Есть ошибка в девятой строке

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь

Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Posted by Christopher Aberly

I’m getting a CS1501 error on my DistanceTo method after writing the code associated with this video. I tried a few things, but I’m not exactly sure what I’m missing here everything looks to be the same as the videos for the «Point» file and the «MapLocation» file. I’m assuming that I’m not passing the right number of arguments into the method, but I can’t figure out how many I’m actually passing to see what might be the problem.

I noticed that the MapLocation Object has 3 parameters (x, y, and map) while the DistanceTo takes only 2 (x,y), but the code in the video didn’t mention modifications to this, so I’m assuming that this is ok.


Below is my code in the MapLocation file

namespace TreehouseDefense
{

class MapLocation : Point
{

public MapLocation(int x, int y, Map map) : base (x, y)
{
  if (!map.OnMap(this))
  {

    throw new OutOfBoundsException(x + "," + y + " is outside the boundaries of the map!");

  }
}


public bool InRangeOf(MapLocation location, int range)
{
    return DistanceTo(location) <= range;

}

}

}


For Point File (object)

using System;

namespace TreehouseDefense

{
class Point
{
public readonly int X;
public readonly int Y;

public Point(int x, int y)
{
  X = x;
  Y = y;
}

public int DistanceTo(int x, int y)
{
  return (int)Math.Sqrt(Math.Pow(X - x , 2) + Math.Pow(Y - y , 2));
}

}
}

2 Answers

Steven Parker

As you observed, «DistanceTo» is defined to take 2 arguments. But it is being called with just one argument («DistanceTo(location)«) in the «InRangeOf» method.

You could change the call to pass in two arguments, but I seem to recall that the project eventually has a 1-argument overload. So if you didn’t miss something, you could just be in an intermediate point right before the overload gets added.


UPDATE: In the Overloading Methods video back in stage 1, the overload of «DistanceTo» was created in the «Point» object. The original takes 2 int arguments, but the new one takes a «Point» (which can also be a «MapLocation»).

Christopher Aberly June 20, 2020 10:57am

I’ve made it through the whole course and gone back through all of the videos to figure out what I’ve done wrong and can’t find it. It looks like the location variable being passed into the DistanceTo method is of MapLocation type, which is an «x», «y», and «map» value. I’m not sure what is going on here, but I’ve written exactly what is in the videos and its not passing through. I don’t recall anything about an override?!

So, to check to see if the additional «map» parameter was causing the issue I changed the type to a «Point»

I tried changing the location type to a Point (from a different class) which definitely only has two input arguments. Note, this is the same class that the «DistanceTo» method is initiated in and on. No dice. Same error.

  • Remove From My Forums
  • Question

  • I’m getting the error error

    CS1501: No overload for method ‘WaitOne’ takes ‘1’ arguments

    When I do an automated build on TFS, but not when I get the source and compile on my machine.

    The thing is, WaitOne(TimeSpan) (off an AutoResetEvent) is VALID!!

    Has anyone else met this?

    • Changed type

      Wednesday, December 17, 2008 10:25 AM

    • Changed type
      Harry Zhu
      Tuesday, January 13, 2009 3:29 AM

Answers

  • The WaitOne(int) and WaitOne(TimeSpan) overloads were added in .NET 3.5, equivalent to .NET 2.0 SP1.  .NET 2.0 only had the overloads that take an additional bool (exitContext argument).  Practically nobody understood what that meant and the wrong value was often used.  To make sure your code runs on the original version of .NET 2.0, you should use the version that takes the additional bool, passing false.


    Hans Passant.

    • Marked as answer by
      BanksySan
      Wednesday, August 5, 2009 8:53 AM

This question already has an answer here:

  • Error cs1501 unity3d 1 answer

I keep getting this error when I run my code and I can’t quite see what the problem is:

error CS1501: No overload for method checkStatus’ takes `1′ arguments

In my enemyHealth script I have:

void Update()
{
    checkStatus (0);
}

public void checkStatus()
{
    if (currentHealth > maxHealth)
        currentHealth = maxHealth;

    if (currentHealth <= 0)
        death();
}

and in my playerAttack script I have:

private void Attack()
{
    enemyHealth eh = (enemyHealth)target.GetComponent ();
    eh.checkStatus (-10);
}


Well, the error message should be plain — you’re calling the checkStatus method with a single argument, while it is declared with no arguments.

Either you need to add an argument to the method declaration (and use it somehow), or you need to change the calls to pass no argument.

It seems that your intent is to either lower the health and check if the character survived — if that’s the case, something like this might work:

public void Damage(int amount)
{
  currentHealth -= amount;

  if (currentHealth > maxHealth)
    currentHealth = maxHealth;

  if (currentHealth <= 0)
    death();
}

Понравилась статья? Поделить с друзьями:
  • Error cs1061 как исправить
  • Error cs1061 unity
  • Error cs1056 непредусмотренный символ
  • Error cs1056 недопустимый символ
  • Error cs1056 unexpected character unity