Click here to Skip to main content
15,310,056 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
C#
for (i = 0; i <= a.GetUpperBound(0); i++)
            {
                t = arbit.Next(1, 10);

                if (Array.IndexOf(a, t) == -1)
                {
                    a[i] = t;

                }
                else
                {
                    goto X;
                }
}

i gor error line in

C#
t = arbit.Next(1, 10);


Thanks for valuable replay
Posted
Updated 8-Nov-11 6:49am
v2
Comments
Amir Mahfoozi 8-Nov-11 12:42pm
   
Firstly you should know that It is not elegant for a programmer to use GOTO in his/her code :-? please rewrite your code so that it doesn't have GOTO.
Richard MacCutchan 8-Nov-11 13:17pm
   
What is arbit and what is the error?
   
Comparison "== -1" is potentially not reliable, use "< 0".
--SA

1 solution

Your code is not clear...
have you declared

Random arbit= new Random(); 


if you have done the above things the test with breakpoints to know what exactly is the error
and yes the use of goto is a bad programming practice
   
v3
Comments
Richard MacCutchan 8-Nov-11 13:17pm
   
Don't use txtspk, spell words in full for clarity.
Karthik. A 8-Nov-11 13:37pm
   
removed txtspeak...

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