Asp. NET Dynamic Web site production (+)--C # (2)

Source: Internet
Author: User
Tags arithmetic operators

The second lesson of C #, still explains the basics of C #.

content :

1.GC: Garbage collection mechanism to reclaim garbage from managed modules.

2. Value types and reference types:

(1) Value type: All numeric types are value types, such as int,byte,short,long,char,bool,float,double, enumerations. The smallest unit of information for a computer is a byte (byte), a byte is a 8-bit (bit), and a letter is a byte.

(2) Reference type: Object, String,object, array. C # has two built-in reference types: The object type and the string type. object is the parent of all types, and you can assign values of any type to a variable of type object, a string type that, once created, cannot be changed and is immutable.

Instantiation of a reference type uses the keyword new.

(3) A value type is a copy of a value, and a reference type is a reference to an address.

(4) Variables are stored in memory, and the heap and stack are included in the memory. All value types are stored in the stack, value type assignment is the copy of the value, the value of the reference type is stored in the heap, the stack contains its reference address, the reference type of assignment, is actually a copy of the address.

(5) to invoke a non-static member (field, method) inside a class, it needs to be called through the object of a class: person p1 = new person (); p1.age=20; To call a static member inside a class, simply call it through the class: Person.age = 20;. Static variables are stored in the static zone.

(6) When instantiating an object of a class, the heap generates all non-static members (fields, methods) inside the class. If the object is not referenced to an instance of an object exception, the object is not instantiated or the object is empty, and there is no content in the heap.

(7) When you instantiate an object of a class, the object of the class is first retrieved within the heap for existence. , a copy will be copied if it exists.

(8) When a class is a static class, all the members in the class are static.

3. Packing and Unpacking:

(1) Boxing: Converts a value type to a reference type.

1 int Ten ; 2 string s = i.tostring ();

(2) Unpacking: Converts a reference type to a value type.

1 string " Ten " ; 2 int i = Convert.ToInt32 (s);

(3) The procedure should avoid packing and unpacking as much as possible, as these two processes may result in some loss of efficiency.

4. Constants, variables: variables contain static variables, member variables-global variables, local variables.

5. Data type conversions:

(1) Implicit conversion: low-precision type to high-precision type, direct turn.

1 int 9 ; 2 double d = i;

(2) Explicit conversion: high-precision type conversion to a low-precision type, you must indicate the type of target to be converted, due to differences in data, some data may be lost.

1 Double 12.34 ; 2 int i; 3 i = (int) D;

6. Operators:

(1) Arithmetic operators: +,-,*,/,%,++,--。

(2) Assignment operator: =,+=,-=,*=,/=,%=,??。

A=b?? C;    // b is null then A=C, NOT null a=b

(3) relational operator: ==,!=,<,<=,>,>=.

(4) logical operator:!,&,|,^,&&,| |.

(5) Precedence: Unary < Two operators < relational operators < logical operators < assignment operators.

7.string class:

(1) string can be viewed as a character array.

1 string " Hello " ; 2 Char [] C = S.tochararray ();

(2) Str. Lenght represents the number of characters inside a string.

(3) Once a string object is created, the object cannot be modified.

(4) When creating a String object, the string data pool (in the heap) is first searched for the same string content object, and if so, the variable is directed to the object, and if not, a new object is created.

(5) Common methods of string:

Compare (): Compares the size of two strings.

Console.WriteLine (String.Compare ("aa","bb"));

The return value is-1. The string compares the size of the ASCII code value.

Equals (): Determines whether two strings are the same, returns true if identical, otherwise returns false.

StartsWith ()/endswith (): Determines whether a string begins or ends with a string, and the return value is true or false.

IndexOf ()/lastindexof (): a specified character or the position of the first or last occurrence of a string.

Substring (): Intercepts the string.

Insert (): Inserts a string at the specified position.

PadLeft ()/padright (): fills a specific character to the left or right to reach the specified length.

Remove (): Deletes the string that is the length of the drawing.

Trim () (removes all leading and trailing blanks), TrimStart () (removes all leading occurrences), TrimEnd () (removes all trailing matches).

CopyTo (): Copies the specified number of characters to the specified position in the character array.

Replace (): the replacement method.

PostScript : Preview, review, extracurricular study.

Asp. NET Dynamic Web site production (+)--C # (2)

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.