While loop execution in C and C# – subtle difference
March 10, 2012
Posted by on
while(int) would not compile in C# and would throw an error and say that the “Cannot implicitly convert type ‘int’ to ‘bool'” . In C# the while loop must strictly have a boolean expression evaluated or while(true) would work fine.
C# doesn’t allow you to use a number as a boolean, even though it’s allowed in C and C++ (where truth is nonzero and falsehood is zero)
some related discussion on stackoverflow.
int i = 10;