如何调试此错误消息“Out arguments not a class of a variable”" [英] How do I debug this error message"Out arguments is not classified as a variable"
问题描述
我在编写的代码中出现此错误,使用方法执行初始值的公式
类似
< pre lang =c#> public static double miuk;
public static double yp = 0 ;
私有 静态 double e_e = Exp( ref 时间, out Yt( out yp)); // 错误
private static double N1,N2,N3,N4 ,C1,C2,C3,C4;
私有 静态 double Exp1 =求和( ref N1, ref C1, ref N2, ref C2, ref N3, ref C3, ref N4, ref C4);
public static double SN( ref double miuK, out double yp)
{
yp = 0 ;
// yp = Yt(ref miuK,out yp);
< span class =code-keyword> return Xp * B * P *((miuK *(1-Math.Exp( - (e_e))) - 1)+(yp * Math.Exp( - ( e_e))* EXP1));
}
public static double Yt( out double yp)
{
yp = 0 ;
return Xp * B * P * miuk *( 1 - Math.Exp( - ( e_e)))+(yp *(Math.Exp( - (e_e))));
}
如何赠送新款价值从重新回到哟一遍又一遍
任何一个有用的想法请其紧急。
private static double e_e = Exp( ref 时间, out Yt( out yp)); // error
您不能将Yt(out yp)
调用作为out参数传递。
out参数必须为变量或字段。它必须是可写的位置。
我不知道你的Exp(...,... ..)
方法是定义的。
(名称 类似于Math.Exp()
不是一个好主意,特别是因为你在这段代码中也使用了Math.Exp()
!)
显示Exp(...,...)
方法,我可以提供帮助...
看起来你真的不需要这么多的参数。
我不确定这个,因为我仍然不知道你实际上想要做什么。
如果你想Yt
到< b>总是操作静态yp
值,和总是更新它然后可能是这样的:
public static double Yt()
{
yp = Xp * B * P * miuk *( 1 - Math.Exp( - (e_e)))+(yp *(Math.Exp( - (e_e))));
return yp;
}
否则,可能更像是:
public static double miuk;
public static double yp = Yt( 0 );
私有 静态 double e_e = Exp(时间,yp);
私有 静态 double N1 ,N2,N3,N4,C1,C2,C3,C4;
私有 静态 double Exp1 =求和( ref N1, ref C1, ref N2, ref C2, ref N3, ref C3, ref N4, ref C4);
public static double SN( ref double miuK, out double yp)
{
// 将这一项作为练习......; - )
yp = 0 ;
// yp = Yt(ref miuK,out yp);
< span class =code-keyword> return Xp * B * P *((miuK *(1-Math.Exp( - (e_e))) - 1)+(yp * Math.Exp( - ( e_e))* EXP1));
}
public static double Yt( double ypParam)
{
return Xp * B * P * miuk *( 1 - Math.Exp( - (e_e)))+(ypParam *(Math.Exp( - (e_e)) ));
}
public static double Exp( double rtime, double ypParam)
{
return Math.Exp( - (Q * F - Yt(ypParam))* Lamda)* rtime;
// 你真的打算将Yt应用于ypParam,因为ypParam IS本身是Yt(yp) ?
// 即,这是Yt(Yt(yp))
}
一般来说,大量使用out
(和/或ref
)参数,以及大量静态
字段(变量)是代码所示的标志在实施之前没有想到! (a.k.a.,代码味道)
I have this error in a code I am writing to use method to carry out a formula with an initial value
like
public static double miuk;
public static double yp = 0;
private static double e_e = Exp(ref time,out Yt(out yp));//error
private static double N1, N2, N3, N4, C1, C2, C3, C4;
private static double Exp1 = Summation(ref N1, ref C1, ref N2, ref C2, ref N3, ref C3, ref N4, ref C4);
public static double SN(ref double miuK,out double yp )
{
yp = 0;
//yp = Yt(ref miuK,out yp);
return Xp*B*P*((miuK*(1-Math.Exp(-(e_e)))-1)+(yp*Math.Exp(-(e_e))*Exp1));
}
public static double Yt(out double yp)
{
yp = 0;
return Xp*B*P*miuk*(1 - Math.Exp(-(e_e))) + (yp*(Math.Exp(-(e_e))));
}
How do I give the new value gotten from the return to "yo" all over again
Any one with useful idea please its urget.
private static double e_e = Exp(ref time,out Yt(out yp));//error
You cannot pass theYt(out yp)
call as an out parameter.
An out parameter must be to a variable or field. It must be a writable location.
I don't know how yourExp(..., ...)
method is defined.
(Having a name that similar toMath.Exp()
is not a good idea, especially since you also are usingMath.Exp()
in this code!)
Show theExp(..., ...)
method and I can probably help...
It looks like you really don't need so many out parameters all over the place.
[Edit: MTH]
I'm not sure about this since I still cannot tell what you're actually trying to do.
If you wantYt
to always operate on the staticyp
value, and always to update it then maybe something like:
public static double Yt() { yp = Xp*B*P*miuk*(1 - Math.Exp(-(e_e))) + (yp*(Math.Exp(-(e_e)))); return yp; }
Otherwise, maybe more like:
public static double miuk; public static double yp = Yt(0); private static double e_e = Exp(time, yp); private static double N1, N2, N3, N4, C1, C2, C3, C4; private static double Exp1 = Summation(ref N1, ref C1, ref N2, ref C2, ref N3, ref C3, ref N4, ref C4); public static double SN(ref double miuK,out double yp) { // fixing this one left as an exercise... ;-) yp = 0; //yp = Yt(ref miuK,out yp); return Xp*B*P*((miuK*(1-Math.Exp(-(e_e)))-1)+(yp*Math.Exp(-(e_e))*Exp1)); } public static double Yt(double ypParam) { return Xp*B*P*miuk*(1 - Math.Exp(-(e_e))) + (ypParam*(Math.Exp(-(e_e)))); } public static double Exp(double rtime, double ypParam) { return Math.Exp(-(Q*F - Yt(ypParam))*Lamda)*rtime; // did you really intend to apply Yt to the ypParam here since the ypParam IS itself Yt(yp)? // I.e., this is Yt(Yt(yp)) }
As a general rule, lots of use ofout
(and/orref
) parameters, and lots ofstatic
fields (variables) is a sign that the code was not thought out before implementing! (a.k.a., "code smell")
这篇关于如何调试此错误消息“Out arguments not a class of a variable”"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!