无过载方法,取0参数呢? [英] No overload for method, takes 0 arguments?

查看:146
本文介绍了无过载方法,取0参数呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

 public static int[] ArrayWorkings()

我可以MyClass.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)

我得到的错误没有过载的方法ArrayWorkings,取0参数。这是为什么?

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

推荐答案

您改变了功能,需要一个参数...所以现在所有的旧函数调用,它传递任何参数,都是无效的。

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
}

这篇关于无过载方法,取0参数呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆