Visual C # 2005 Quick Start statement bool variable

Source: Internet
Author: User
Tags bool

Unlike the real world, in the programming world, everything is black or white, right or wrong, true or false. For example, suppose you create an integer variable named x, assign the value 99 to X, and then ask, "Does x contain a value of 99?" "The answer is obviously affirmative. If you ask: "Is x less than 10?" "The answer is obviously negative. These are examples of Boolean (Boolean) expressions. A Boolean expression must evaluate to TRUE or false.

Note that not all programming languages will respond to these questions. For example, an unassigned variable has an undefined value and cannot be said to be less than 10. Because of this, novice in writing C and C + + program error prone. The Microsoft Visual C # compiler's solution to this problem is to make sure that a value has been assigned to it before checking for a value. If you attempt to check the contents of an unassigned variable, the program will not compile.

Microsoft Visual C # provides a data type named BOOL. A bool variable can hold only one of two values: TRUE or FALSE. For example, the following 3 statements declare a bool variable named Areyouready, assign a true value to it, and output its value on the console:

BOOL Areyouready;

Areyouready = true;

Console.WriteLine (Areyouready); Output true

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.