[Solved] No overload for method, takes 0 arguments?

I have:

 public static int[] ArrayWorkings()

I can call it happily with MyClass.ArrayWorkings() from anywhere. But I want to build in some extra functionality by requiring a parameter such as:

 public static int[] ArrayWorkings(int variable)

I get the error No overload for method ArrayWorkings, takes 0 arguments. Why is this?

Solution #1:

You changed the function to require one parameter… so now all of your old function calls, which passed no parameters, are invalid.

Is this parameter absolutely necessary, or is it a default value?

if it is a default then use a default parameter or an overload:

//`variable` will be 0 if called with no parameters
public static int[] ArrayWorkings(int variable=0)  

// pre-C# 4.0
public static int[] ArrayWorkings()
{
    ArrayWorkings(0);
}

public static int[] ArrayWorkings(int variable)
{
    // do stuff
}
Respondent: Ed S.
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.