Data Type in C #

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.