The note of learning ASP. NET [11] About Forced type conversion of. Net Variables
Source: Internet
Author: User
When assigning a data type to another data type variable, explicit type conversion may be required. For example, if you assign an int variable to a short variable, because the short variable storage value range is smaller than the int type, data may be lost. In this case, we need to perform explicit data type conversion. It is not required to assign the short type to the Int or long type. 1. use the forced type conversion operator for example: required value = (short) (required value + bytevalue); here we use "(short) "to convert the values of future value + bytevalue (the value obtained by the default addition is int type) to the short type and then assign it to the short type variable mongovalue2. use the convert class, convert class has many types of Conversion Function examples: convert. tosingle (longvalue); here we use the convert class to convert a long variable longvalue to the float type. 3. Using the parse method, the parse method can convert a string to another data type. Example: single. parse (longvalue. tostring (); here is to convert a long variable to the float type. We first use the tostring method of the long variable to convert the long type to a string, then, the parse method of the single class is used in the outer layer to convert the converted string to the float type data.
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