I am not sure what the problem is but I keep receiving this error when I try to use a while statement in my code.
Invalid token \'while\' in class,
C# does not provide writing the for, while or foreach kind of looping statement directly inside the class. These statements should be within a user defined method, main method or constructors.
class Array
{
public static void main(string[] args)
{
int[] n = new int[10]; /* n is an array of 10 integers */
/* initialize elements of array n */
for (int i = 0; i < 10; i++)
{
n[i] = i + 100;
}
/* output each array element's value */
foreach (int j in n)
{
int i = j - 100;
Console.WriteLine("Element[{0}] = {1}", i, j);
}
}
}