C # Supplements's trivia (i)

Source: Internet
Author: User
Small Knowledge (i)

Var:

Initialization must have assignment, var i; (wrong).

Objects of type Var are not allowed to change types while they are running. (such as: Var I=1; I= "hello!" will go wrong)

var declares only local variables.

Dynamic

You can not assign a value when initializing.

An object of type dynamic can be given to that type during the run. (such as: Dynamic I=1; I= "hello!" does not go wrong)

Can be declared as a global variable.

var and dynamic: Typically used when the variable type is not deterministic.

Decimal

High precision Decimal, Range: 1.0*10^-28 to 7.9*10^28, precision 28 bits. Typically used to represent money. Float/double Accuracy 7/15 bit, it will help you "erase 0" by using this float/double two type to represent the currency.

Decimal Default value: 0.0M

Float Default value: 0.0F

Double Default value: 0.0D

Char

The char character type is assigned a value of 3

Char c= ' d ';

Char c= ' \x0068 '; Hexadecimal

Char c= ' \u0068 '; Unicode representation

Char c= (char) 68; Reshape conversion char.

Default value: ' \x0000 '

Octal and 16 binary:

In C #, shaping is represented in 10 binary notation, with the 8 binary format specifier "O" or "O" and the 16 binary format specifier being "x" or "X" compiled with errors (such as: int i = o73; error).

Use I when I need to output 8 or 16 binary. ToString ("X").

    • Display 2 binary WriteLine (convert.tostring (231,2));

    • Display 8 binary WriteLine (convert.tostring (231,8));

    • Display 16 binary WriteLine (convert.tostring (231,16));

    • Displays 16 binary WriteLine (i.ToString ("X")) and lowercase.

    • Displays 16 binary WriteLine (i.tostring ("X")) and uppercase.

PadLeft and PadRight

The left or right padding of the output string is either right-justified or left-aligned.

ToString (). PadLeft (8); The output string length is 8, and the left side is blank.

Parse:

Parse Parse, converts the string representation of a number to a number equivalent.

such as: Int.parse (String); Double.Parse (string); Decimal.Parse (string) and so on.

var and dycimal do not have a parse method.

Note: When a string of 16 binary numbers is converted to int with the parse (String,system.globalization.numberstyle) method, the second enumeration parameter is selected Hexnumber.

How does the 2 binary string and the 8 binary string parse into int? It is not known yet ... Who's the master to say???

Encoding:

A conversion between a string and a byte array. System.Text.Encoding class

Byte[]←getbytes (String) method to convert a string to a byte array.

String←getstring (byte[]) method to convert a byte array to a string.

Encoding properties:

    • Encoding.default gets the encoding of the system's current ANSI code page

    • ENCODING.UTF7 Get UTF7 encoding format

    • Encoding.UTF8 Get UTF8 encoding format

    • Encoding.ascii getting the encoding for the 7-bit ASCII character set

    • Encoding.unicode obtaining encoding for a specific order in Unicode format

    • Byte[] B=system.text.encoding.unicode.getbytes (s);

Enum Enum:

User-defined data types. The value of the Enum enumeration starts with 1, except for customizations. Separated by a comma, the value can be assigned to an integer.

String conversion Specific enumeration:

Object←enum.parse (type enumtype,string value);

Such as:

Color col= (color) enum.parse (typeof (color), "white");

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

   Enum e    {    }

struct Structure:

User-defined data type, struct type. A struct can contain constructors, constants, fields, methods, properties, indexers, and operators.

Structure is a value type and the address is assigned on the stack

Both structs and classes can inherit interfaces.

Structs cannot be integrated, classes can.

Structs do not have destructors, classes have.

struct s    {    }

The above is the C # supplements of the Small knowledge (a) of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.