I previously had following code:
public class Program
{
public static void Main(string[] args)
{
int i = 0;
while(condition)
{
.........
.........
if (condition)
{
i = 6;
Console.WriteLine("Inside Block :" +i);
}
else
{
i = 7;
Console.WriteLine("After block : " + i);
}
}
}
}
Later, i figured that i don't need any conditions and want to assign 6 to variable i
each time. So i commented out the code but by doing so I made a silly mistake and so now my code looks like following:
public class Program {
public static void Main(string[] args)
{
int i = 0;
while(condition)
{
.........
.........
// a block without condition
{
i = 6;
Console.WriteLine("Inside Block :" +i);
}
}
}
}
As you can see, by mistake i just commented out/deleted the line with if
condition but forgot to remove the blocks.Now, what does this block means here. It gets executed every time which i wanted anyway but why it is not giving any error while compiling?
Do we have any terminology/concept here? I know about Initializer Block
in Java
but that is not what happening here. Will it work differently in Multi-Threading
environment?
Any info will be really helpful.