我正在尝试从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 :(得分:3)
您正在调用方法而不提供必要的参数来调用它。这是我的意思的一个例子:
public class Program
{
public void Main()
{
int answer = GetAnswer(4); //4 is the argument
//don't do `GetAnswer()`;
Console.WriteLine(answer);
}
public static int GetAnswer(int num)
{
return (num*0) + 42;
}
}