Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
320 views
Welcome To Ask or Share your Answers For Others

1 Answer

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...