On the various data types in C # language, and the conversion between data types

Source: Internet
Author: User
Tags string to number

What is a data type?

Data type, Baidu Encyclopedia is interpreted as follows: The data type is defined as a collection of values and a set of operations defined on the value set. Such an explanation may not be too esoteric for a beginner.

Simply put, the data type is the collation of data of different lengths . The appearance of data type is to solve the problem of reasonable preservation of data of different lengths in computer. In order to divide the data into different memory sizes, it is necessary to use big data when programming, and to make full use of memory. To optimize the use of resources to reduce waste of memory.

What are the data types?

Type description Range Default value

Common types of data:
    • Types of shaping are:int, short, long, byte.
    • Float type:float 32-bit single-precision floating point type (note: When this type of data is entered, it should be added F after the data, such as 3.14f).

a double 64-bit double-precision floating-point type.

    • Character type:char a single-character type definition is represented with a pair of single quotation marks (' 1 ').

string String type definition is denoted by a pair of double quotation marks ("abc").

    • bool : type bool is a special type of data that has a value of true or FALSE, which is true or false, and an expression of that type is executed only when the return value is True (true).
Conversions between data types:
    • conversion between int and double :
    • 1, int to double: because the int type data uses the memory length is less than double, so the program here adopts the law of implicit conversion (automatic conversion), for example:

In this expression, the variable a of type int is b=a by the expression, and the value of a is assigned directly to the program without error.

2,double to int, the conversion of this order should be noted, because, double to int need to use the display conversion ( cast ), for example: When we do not need to cast the program here will be an error:

So here's what you need to write: a= (int) b; Convert the value of B to a variable of type int, and then assign to the variable a of type int to be successful.

    • any type of round string : The rule is (the variable name to be converted.) Tostring ()). The key word is the point ToString (), where it is important to note that the T in ToString must be capitalized. Example:
    • string to number (int or double): the rule is Int. Parse (string variable name) or double. Parse (string variable name); Example:

It is also important to note that the first letter of the parse is capitalized.

Summarize:

    1. Data type is the computer in order to achieve the optimal configuration of memory, the data according to different memory length to partition data blocks.
    2. Data types are divided into integer type, floating point type, character type, bool type four categories.
    3. There are three main categories of conversions between data types:
    • int and double conversions:( keywords (int variable name).
    • any type goes to the string keyword variable name. Tostring ().
    • String to Number: keyword type name. Parse (the variable name to be converted).

2018-06-11

On the various data types in C # language, and the conversion between data types

Related Article

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.