In C ++, values of the bool type can be converted to values of the int type. False is equivalent to zero, and true is equivalent to a non-zero value. However, in C #, there is no mutual conversion between the bool type and other types. For example, the following if statement is invalid in C # And is valid in C ++:
Int x = 123;
If (x) // note: in C #, this statement is incorrect.
{
Printf ("X is non-zero value .");
}
To test the int type variable, you must explicitly compare the variable with a value (such as zero), as shown below:
Int x = 123;
If (X! = 0) // method of determining C #
{
Console. Write ("the value of X is nonzero .");
}
Function Description: enter a character from the keyboard and thenProgramCheck whether the entered character is a letter. If the entered character is a letter, the program checks whether it is in upper or lower case. These checks are executed using isletter and islower (both return the bool type.
Using System;
Public Class Booltest1
{
Static Void Main ()
{
Console. Write ( " Enter a letter: " );
Char C = ( Char ) Console. Read ();
If (Char. islower (c ))
{
Console. writeline ("This character is a lowercase letter.");
}
Else
{
Console. writeline ("This character is an uppercase letter.");
}
}
}
There is a predefined implicit conversion from byte to short, ushort, Int, uint, long, ulong, float, double, or decimal.
Note:
You cannot implicitly convert non-text numeric values of a larger storage range to bytes.
For example, byte z = x + y;
The preceding value assignment statement produces a compilation error because the arithmetic expression on the right of the value assignment operator is calculated as int by default.
To solve this problem, use forced conversion:
Byte z = (byte) (x + y );