using System;
class CodeFile1
{
static void Main()
{
int[] sample = new int[100];
inti;
for(i=0;i<10;i=i+1);
sample[i] = i;
for(i=0;i<10;i=i+1)
Console.WriteLine("This is sample["+i+"]:"+sample[i]);
}
}
I'm making a sample app. Compiling the above,
This is sample[0]:0 This is sample[1]:1......
is not
This is sample[0]:0 This is sample[1]:0......
I don't know the cause.Is the loop statement strange?
c#
for(i=0;i<10;i=i+1);
There is a semicolon, so the contents of the for statement end there.
for(i=0;i<10;i=i+1){
}
Would it be easy to understand if it is equivalent to ?
var sample=new int[100];
for (vari=0;i<10;i++)
{
sample[i] = i;
}
for (vari=0;i<10;i++)
{
Console.WriteLine("This is sample["+i+"]:"+sample[i]);
}
© 2024 OneMinuteCode. All rights reserved.