Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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"]);

I got error near the
x = x_loopVariable;<br />

Thanku for valuable raplay
Posted
Updated 2-Nov-11 19:16pm
v3
Comments
P.Salini 3-Nov-11 0:54am    
What error you got
Sergey Alexandrovich Kryukov 3-Nov-11 1:06am    
You are right, description of the problem and the code are insufficient, but in this particular case... some of deductive method... elementary, Watson! -- please see my solution.

(However I prefer accurate questions, not riddles :-))
--SA
Sergey Alexandrovich Kryukov 3-Nov-11 0:55am    
No, no, such question could no be correct. Declaration of "x" is not shown; but this is critical. It needs correct and complete error or exception report.
--SA

1 solution

Of course.

Let's see: x_loopVariable is object. Assuming x = 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 know x is object, cannot be a method. You could use "[]" instead, which would work if the type of x had an indexed property ("this"). But as x 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
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900