【发布时间】:2014-01-04 22:05:03
【问题描述】:
我正在尝试从 main 调用我的一个方法,但我收到一条错误消息:
方法“NextImageName”没有重载需要 0 个参数
不知道如何解决这个问题 在我的主程序上,我调用了我的方法“BuildingBlock.NextImage();”这是我收到错误消息的地方。
class BuildingBlock
{
public static string ReplaceOnce(string word, string characters, int position)
{
word = word.Remove(position, characters.Length);
word = word.Insert(position, characters);
return word;
}
public static string GetLastName(string name)
{
string result = "";
int posn = name.LastIndexOf(' ');
if (posn >= 0) result = name.Substring(posn + 1);
return result;
}
public static string NextImageName(string filename, int newNumber)
{
if (newNumber > 9)
{
return ReplaceOnce(filename, newNumber.ToString(), (filename.Length - 2));
}
if (newNumber < 10)
{
return ReplaceOnce(filename, newNumber.ToString(), (filename.Length - 1));
}
if (newNumber == 0)
{
return ReplaceOnce(filename, newNumber.ToString(), ((filename.Length - 2) + 00));
}
return filename;
}
【问题讨论】:
-
请指出是哪一行导致了这个错误。错误信息如何让您感到困惑?
-
您需要将参数传递给您的方法。
-
这些方法都没有带0参数,编译器很对,考虑给你的方法传递一些参数。
-
这些代码不会出现此错误。你的问题在别的地方。调试你的代码,看看你在哪里。
-
发布到 SO 时,您应该包括编译器抱怨的实际行(提示:双击错误消息,它会带您到那里)。此外,您应该包括 EXACT 错误消息。您输入的内容未包含所有详细信息。
标签: c# overloading