Small knowledge (1), small knowledge (

Source: Internet
Author: User

Small knowledge (1), small knowledge (

Var:

Dynamic:

VAR and DYNAMIC: used when the variable type is not determined.

Decimal:

High-Precision decimal places, ranging from 1.0*10 ^-28 to 7.9*10 ^ 28, with a precision of 28 digits. It is generally used to represent money. Float/double has a precision of 7/15 bits. When the float/double type is used to represent the currency, it will help you "erase ".

Default Value of decimal: 0.0 M

Float default value: 0.0F

Double default value: 0.0D

Char:

The char character type has three values.

Char c = (char) 68; Integer Conversion char.

Default Value: '\ x000000'

Octal and hexadecimal:

In C #, the integer is represented in decimal format, an error occurs when the "o" or "O" and hexadecimal format specifiers are "x" or "X". For example: int I = o73; error ).

You can use I. ToString ("x") to output the hexadecimal or hexadecimal values.

Display binary WriteLine (Convert. ToString (231,2 ));

Display octal WriteLine (Convert. ToString (231,8 ));

Display hexadecimal WriteLine (Convert. ToString (231,16 ));

Display hexadecimal WriteLine (I. ToString ("x"); lower case.

Display hexadecimal WriteLine (I. ToString ("X"); display uppercase.

PadLeft and PadRight

Fill spaces on the left or right of the output string to align right or left.

ToString (). PadLeft (8); the output string length is 8, and spaces are filled on the left.

Parse:

Parse parsing, SetNumberOfString RepresentationConvert the form to a number.

For example, int. parse (string); double. parse (string); decimal. parse (string.

Var and dycimal have no parse method.

Note: Use the Parse (string, System. Globalization. NumberStyle) method when converting a hexadecimal number to an int. Select HexNumber as the second enumeration parameter.

How can I resolve a binary string and an octal string to an int? I don't know yet ...... Which of the following experts will talk about it ???

Encoding:

Conversion between string and byte array. System. Text. Encoding class

Byte [] bytes GetBytes (string) method to convert a string to a byte array.

String bytes GetString (byte []) method to convert a byte array to a string.

Encoding attributes:

Encoding. Default gets the system's current ANSI code page Encoding

Encoding. UTF7 get the UTF7 Encoding format

Encoding. UTF8 get UTF8 Encoding format

Encoding. ASCII get the Encoding of the 7-bit ASCII character set

Encoding. Unicode get the Encoding of the Unicode format in a specific order

Byte [] B = System. Text. Encoding. Unicode. GetBytes (s );

Enum enumeration:

User-Defined data type. The enum enumerated value starts from 1, except for the custom value. Separated by commas (,). You can assign values to integer values.

String Conversion-specific enumeration:

Object quota Enum. parse (type enumType, string value );

For example, color col = (color) Enum. parse (typeof (color), "white ");

Note: If the string does not match the enumeration, an error occurs.

Enum e

{

}

Struct structure:

User-Defined data type, structure type. The structure can contain constructors, constants, fields, methods, attributes, indexers, and operators.

The structure is a value type and the address is allocated on the stack.

Both structures and classes can inherit interfaces.

The structure cannot be integrated, and the class can.

The structure has no destructor, and the class has.

Struct s

{

}

 

See C # programming practices. Edited by Tsinghua University Press and FU Qiang Ding Ning. Chapter 3.

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.