Data type:

Source: Internet
Author: User

String (string)---to put a string of characters that need to be caused by ""
Integer (int)----Integral type-----cannot be added "" "4 bytes long (8 words) Short (2 bytes) ting (micro-shaping 1 bytes) 1 bytes = 8 bits =1b=8bit
int a=456; 1kb=1024b
int b=789;
Console.WriteLine (A+B);
Decimal type, float type (float,double)
float--single-precision floating point 4 bytes
double--double-precision floating-point type. 8 bytes
Double a=3.14;
float =3.14f;
Boolean type (BOOL).  Logical type, either or. True, false 1 bytes
BOOL A=true;
BOOL B = false;

Character type (char). Single character type with single quote ' '
char c = ' 4 '
Two. Variables
Defined first, then used. Defining variable names is not a duplicate name

Defined:
Data type variable name can write value or do not write
int A;
int B = 20;

Assignment Amount name = value


Use the variable name directly,


General rules for variable naming
1. Variable naming generally consists of alphanumeric underscores
2. The variable name can begin with only a letter or an underscore number cannot be the beginning of a variable name
3. Variable names cannot be duplicated with system keywords

Three. Constants
The amount of value that cannot be changed during the running process is constant, the amount of the value that can be changed during the run is variable

Literal constants
Symbol constants. Definition: Add the const keyword to the left of the variable definition.
const int B = 20, plus const is constant
Note: Symbolic constants must be assigned when they are defined.
Application of Symbolic constants: In some repeated use of complex data generally like to replace him with constants, practical constants for programming operations.


Type conversions
The computer can only operate on the same type of data, the different types of data can not be directly computed, if the different types need to be converted (automatic conversion, casting)
int a= 10
Double b=3 Console.WriteLine (A/b); First turn the value of a into a decimal type
Cast int a= 9
Double b=3
int c = A/(int) b, or int c = (int) (A/b);
automatic conversion; The computer automatically converts the type according to the operation data. The principle is that, as long as the type is not lost, the data is converted.
Tiny--short--int--long---Double
Forced conversion; a type becomes another type, which is enforced when the computer does not automatically convert, but it is possible to lose data.

Syntax: 1. Add parentheses to the left of the converted data, and the parentheses to write the target type to be converted.
int a = (int) 3.14;
2. Use Convert.toxxx () conversion.
int a=10;
Double b = 3.0;
int c = A/convert.toint32 (b);

string s = "7896";
int n = convert.toint32 (s);

Data type:

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.