vb.net Boolean Data type

Source: Internet
Author: User
Tags numeric value

Boolean Data Type

from String to Boolean when type conversion only "True" , "False" and numbers can be converted to Boolean Type , all other types will have an error.

For example, if you execute the following code, an error occurs: The conversion from the string "" to the Type "Boolean" is invalid.

Dim Test as Boolean

Test = CBool ("")

The following is quoted from: msdn.microsoft.com

A Boolean variable is stored as a numeric value of 16 bits (2 bytes), but only True or False. Use the keyword True and False to assign a boolean variable to one of these two states.

When you convert a numeric data type to a boolean value, 0 converts to False, and all other values are converted to True. When you convert a Boolean value to a numeric type,False converts to 0, andTrue converts to-1.

Attention The ToInt32 method of the convert class in the System namespace converts True to +1. If you need to convert a Boolean value to a numeric data type, note the conversion method that you are using.

warning never write code that relies on the equivalent value of True and False . Whenever possible, you should limit the use of Boolean variables as logical values, which is the purpose of designing a boolean variable. If you need to mix Boolean and numeric values, be sure to use the appropriate conversion keywords.

The equivalent. NET data type is System.Boolean.

Reference URL: http://msdn.microsoft.com/zh-cn/library/cc437484 (vs.71). aspx

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.