我收到以下代码错误 [英] I got Error Below code
本文介绍了我收到以下代码错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尊敬的所有专家,
Dear All Experts,
foreach (object x_loopVariable in dt.Rows)
{
x = x_loopVariable;
if (x("Selected") + 1 == x("correct"))
{
marks += 1;
}
}
r.Items.Add(dt.Rows [ctr] ["Choice1"]);
r.Items.Add(dt.Rows[ctr]["Choice1"]);
I got error near the
x = x_loopVariable;<br />
附近出现错误
感谢您提供宝贵的raplay
Thanku for valuable raplay
推荐答案
当然.
让我们看看:x_loopVariable
是对象.假设x = x_loopVariable
可以编译,x
也是对象,否则分配兼容性将不允许编译此行.
在下一行中,存在两个问题:()"是方法调用的语法,但是我们已经知道x
是对象,不能是方法.您可以改用"[]",如果x
的类型具有索引属性("this"),该方法将起作用.但是由于x
是对象,因此不会编译,因为它不具有此属性.您可能需要某种类型的大小写,以匹配实际对象的某些运行时类型.我在这里撇开了可维护性的问题.
现在,考虑一下:这种微妙的"猜测!它们是完全多余的,因为您只需要提供足够的信息即可.您为什么认为我们需要阅读您的想法?这次我设法做到了(很好,几乎是:-)),但是下次可能不起作用.
—SA
Of course.
Let''s see:x_loopVariable
is object. Assumingx = x_loopVariable
compiles,x
is also object, otherwise assignment compatibility would not allow compilation of this line.
In next line, there are two problems: "()" is a syntax for method call, but we already knowx
is object, cannot be a method. You could use "[]" instead, which would work if the type ofx
had an indexed property ("this"). But asx
is object, it would not compile because it does not have this property. You might need a type case to some relevant run-time type of the actual object. I leave aside the problem of maintainability here.
And now, think about it: such "delicate" speculations! They are completely redundant, because you simply had to provide sufficient information. Why do you think we need to read your mind? This time I managed to do that (well, almost :-)) but next time it might not work.
—SA
这篇关于我收到以下代码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文