I have this rather strange(probably stupid) question: I have two classes:
class Sharp {
public int x;
public Sharp(int j) {
x = j;
}
}
and
the class containing the Main method:
Obviously I can not initialize many objects and assign them to the same variable. So when I do to do this
Sharp ooo = new(7);
Sharp ooo = new(9);
The compiler throws an error which is absolutely fine.
But for some reason the following code compiles fine:
for (int i = 0; i <= 5; i++) {
Sharp ooo = new(i);
Console.WriteLine(ooo.x);
}
I am trying to understand why would that compile if I am trying to initialize the ooo times. Please help me.