In C++, a value of type bool can be converted to a value of type int; in other words, false is equivalent to zero and true is equivalent to nonzero values. In C#, there is no conversion between the bool type and other types. For example, the following if statement is invalid in C#:
int x = 123;
// if (x) // Error: "Cannot implicitly convert type 'int' to 'bool'"
{
Console.Write("The value of x is nonzero.");
}
To test a variable of the type int, you have to explicitly compare it to a value, such as zero, as follows:
if (x != 0) // The C# way
{
Console.Write("The value of x is nonzero.");
}