重载方法的 0 个参数 [英] 0 arguments for overload method
本文介绍了重载方法的 0 个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从 main 调用我的方法之一,但收到一条错误消息:
I'm trying to call one of my methods from main but I'm getting an error message:
方法NextImageName"没有重载需要 0 个参数
No overload for method "NextImageName" takes 0 arguments
不知道如何解决这个问题在我的主要我调用了我的方法BuildingBlock.NextImage();"这是我收到错误消息的地方.
Not sure how to fix this On my main I called for my method "BuildingBlock.NextImage();" This is where I get an error message.
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;
}
推荐答案
您在调用方法时没有提供调用它所需的参数.这是我的意思的一个例子:
You are calling the method without supplying the necessary arguments to invoke it. Here's an example of what I mean:
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;
}
}
这篇关于重载方法的 0 个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文