Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No overload for method, takes 0 arguments?

Tags:

c#

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?

like image 666
user1166981 Avatar asked Dec 26 '22 22:12

user1166981


1 Answers

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
}
like image 101
Ed S. Avatar answered Jan 09 '23 15:01

Ed S.