编译器错误:运营商QUOT; *"和" + QUOT;不能应用 [英] compiler error: operator "*"and"+" cannot be applied
问题描述
我问这样的问题,昨天,但我没有得到关于它很好的答案
在下面,为什么我不能用code *和+在最后一行?和什么方式来解决?谢谢
私人无效bigzarb(INT U,INT V)
{
双N;
INT X = 0;
诠释Ÿ;
INT瓦特= 0;
INT Z者除外;
串[1 = textBox7.Text.Split(,);
INT [] = NUMS新INT [i.Length]
对于(INT计数器= 0;反< i.Length;反++)
{
NUMS [窗口] = Convert.ToInt32(一[窗口]);
}
U = NUMS [0];
双firstdigits = Math.Floor(Math.Log10(U)+ 1);
V = NUMS [1];
双seconddigits = Math.Floor(Math.Log10(ⅴ)+ 1);
如果(firstdigits> = seconddigits)
{
N = firstdigits;
}
其他
{
N = seconddigits;
}
如果(U == 0 || v == 0)
{
的MessageBox.show(下称乘为0);
}
字符串阈值= textBox9.Text;
INT intthreshold = Convert.ToInt32(阈值);
INT INTN = Convert.ToInt32(N);
如果(INTN< = intthreshold)
{
双重UV = U * V;
字符串struv = uv.ToString();
的MessageBox.show(struv);
}
其他
{
INT米= Convert.ToInt32(Math.Floor(N / 2));
X = U%^ 10米;
Y = U / 10 ^米;
W = v%的10 ^米;
Z = V / 10 ^米;
bigzarb(X,W)*(10 ^ M)+(bigzarb(X,W)+ bigzarb(W,Y))* 10 ^ M + bigzarb(Y,Z); ///编译器提供的错误操作符*和+可以不被应用于type'void'and'int的操作数的
///和编译器提供的错误操作符*和+可以不被应用于类型的操作数无效和无效
}
}
乔恩斯基特已经回答了这个问题,但我虽然我会更明确的解释到底发生了什么在这条线......
的 bigzarb(X,W)*(10 ^ M)+(bigzarb(X,W)+ bigzarb(W,Y))* 10 ^ M + bigzarb(Y,Z );
让我们把它分成部分。
第一条语句
bigzarb(X,W)
但你会从Jon的回答看 - 你是不是返回此方法的值...
私人无效bigzarb(INT U,int v)按
现在让我们来替换位与它的现在,我们已经解释了它的实际值:
[无效] *(10 ^ M)+(bigzarb(X,W)+ bigzarb(W,Y))* 10 ^ M + bigzarb(Y,Z);
这同样适用于所有的其它呼叫bigzarb - 让我们来取代那些太...
[无效] *(10 ^ M)+([空] + [空])* 10 ^ M + [无效]
所以,你的问题是,为了使用数学运算符,你需要的数字,每边 - 但你没有数字,因为你的方法是无效的。
。您可以改变你的方法返回一个数字 - 但要知道递归的......当你调用这个方法,它自称三次,每次这些电话将导致另外三个调用方法。不好!</ P>
i asked like this question yesterday but i didnt get good answer about it
in the code below why i cant use * and + in last line?and whats the way to solve that?thanks
private void bigzarb(int u,int v)
{
double n;
int x=0;
int y;
int w=0;
int z;
string[] i = textBox7.Text.Split(',');
int[] nums = new int[i.Length];
for (int counter = 0; counter < i.Length; counter++)
{
nums[counter] = Convert.ToInt32(i[counter]);
}
u = nums[0];
double firstdigits =Math.Floor(Math.Log10(u) + 1);
v = nums[1];
double seconddigits = Math.Floor(Math.Log10(v) + 1);
if (firstdigits >= seconddigits)
{
n = firstdigits;
}
else
{
n = seconddigits;
}
if (u == 0 || v == 0)
{
MessageBox.Show("the Multiply is 0");
}
string threshold = textBox9.Text;
int intthreshold = Convert.ToInt32(threshold);
int intn = Convert.ToInt32(n);
if (intn <= intthreshold)
{
double uv = u * v;
string struv = uv.ToString();
MessageBox.Show(struv);
}
else
{
int m =Convert.ToInt32(Math.Floor(n / 2));
x = u % 10 ^ m;
y = u / 10 ^ m;
w = v % 10 ^ m;
z = v / 10 ^ m;
bigzarb(x, w) *( 10 ^ m) +(bigzarb(x,w)+bigzarb(w,y))*10^m +bigzarb(y,z);///compiler gives error operator "*"and"+" cannot be applied to operands of type'void'and'int'
///and compiler gives error operator "*"and"+" cannot be applied to operands of type 'void' and 'void'
}
}
Jon Skeet has answered this question, but I though I would be more explicit to explain exactly what is happening on this line...
bigzarb(x, w) *( 10 ^ m) + (bigzarb(x,w)+bigzarb(w,y))*10^m +bigzarb(y,z);
Let's break it into sections
The first statement is
bigzarb(x, w)
But as you'll see from Jon's answer - you are not returning a value from this method...
private void bigzarb(int u,int v)
Now let's replace that bit with it's actual value now we've explained it:
[void] *( 10 ^ m) + (bigzarb(x,w)+bigzarb(w,y))*10^m +bigzarb(y,z);
The same goes for all of the other calls to bigzarb - so let's replace those too...
[void] * ( 10 ^ m) + ([void] + [void]) * 10 ^ m + [void];
So your problem is, in order to use mathematical operators, you need numbers on each side - but you don't have numbers because your method is void.
You could change your method to return a number - but be aware of recursion... when you call this method, it calls itself three times and each of those calls will result in a further three calls to the method. Not good!
这篇关于编译器错误:运营商QUOT; *&QUOT;和&QUOT; + QUOT;不能应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!