1

我有这样的功能:

example(long a,long b,string c,DateTime d,DateTime e,out decimal f)

当我试图调用它时,我正在这样做:

long a =1;
long b=2;
string c="";
DateTime d=DateTime.Now;
DateTime e=DateTime.Now;
decimal f=0;

example(a,b,c,d,e,f) --> Here is giving me the error : the best overloaded method has some invalid argument 

你能帮我解决这个问题吗

4

4 回答 4

3

你需要打电话example(a,b,c,d,e, out f);

并且不需要初始化f,最好不要这样做(这是误导):

//decimal f=0;
decimal f;
于 2013-09-17T06:58:49.313 回答
1

由于d是一个out参数,因此您需要out关键字(在 C# 中):

example(a, b, c, d, e, out f)
于 2013-09-17T06:59:43.340 回答
0

您还需要out在方法调用中使用关键字:

example(a, b, c, d, e, out f);

另请参阅:out 参数修饰符(C# 参考)

于 2013-09-17T06:59:09.573 回答
0

out当你调用你的方法时,你也应该使用关键字;

example(a,b,c,d,e, out f);

MSDN;

out 关键字导致参数通过引用传递。这类似于 ref 关键字,只是 ref 要求在传递变量之前对其进行初始化。要使用 out 参数,方法定义和调用方法都必须显式使用 out 关键字。

于 2013-09-17T06:59:19.057 回答