C # Have you read all of these basics? (1) ----- for beginners only,

Source: Internet
Author: User

C # Have you read all of these basics? (1) ----- for beginners only,

1. Comment (if you do not write a comment, it is a rogue, and the name is nonsense)
'//' Is generally used for annotation functions and annotation classes.
2. Shortcut Keys
Ctrl + k + d (alignment fails due to syntax errors)
Ctrl + j (only prompt is displayed in the quick pop-up)
Shift + end, shift + home keys from the beginning of the row to the end of the row, from the end of the row to the first of the row;
Ctrl + k + c comment ctrl + k + u uncomment
Alt + shift + f10 open description Reference Space.
F1 to msdn
F12 to definition

3. Data Type
Decimal money = 5000 m; (money type)
String and string are the same in c. String is a common type used by the. net platform. string is a unique feature in c #. Both of them are mapped to the System. class.
4. Naming rules
* 1. Camel naming rules (mostly used for variable naming): the first letter is lowercase, And the other words are capitalized.
* 2. Pascal naming rules (mostly used for class or method naming): the first letter of all words is capitalized.
5. placeholders
Usage method: First open a pit and then fill in a pit.
Console. WriteLine ("... {0},... {1},... {2}", n1, n2, n3 );
6. escape characters
\ N: line feed, but \ n is not recognized in windows, only \ r \ n is known;
\ ": Outputs halfwidth quotation marks
\ T: tab key (typographical)
\ B: returns the unsigned value. The first and last placed records are invalid, but only one unsigned value is returned.
@: 1. Cancel the escape Function of \ in the string. 2. Retain the original format output.
7. Enumeration
===== Conversion between enumeration and int and string ===
@ 1. The Enumeration type can be converted to the int type by default. The Enumeration type is compatible with the int type.
@ 2. Convert the enumerated type to string and use toString ();
Enumeration type object name = (Enumeration type) Enum. Parse (typeof (enumeration name), string s );
8. Attributes
Idiom: uppercase letters at the beginning of a property and lowercase letters at the beginning of a field.


Class Person
{
Private int age;

Public int Age
{
Set
{
This. age = value;
}
Get
{
Return this. age;
}


}
9. If there is no global variable in c #, you can only use static fields to simulate global variables.
10. Three parameters in c #
1) out parameters:
If multiple values of the same type are returned in a method, you can consider returning an array.
However, when multiple different types of values are returned, the out clause is required. An out statement can return multiple identical values or different values.
In fact, the out function is used to return multiple values of the called function. It is opposite to the general return direction.
Note: The out variable must be assigned a value in the called function.
2) ref parameters:
A variable can be brought into a method for change. After the change is completed, the changed value is taken out of the method.


Main ()
{
Int s = 10;
Test (ref s );


}
Test (ref s1)
{
S1 + = 3
}
3) parame parameters:
Variable parameters
Take the type in the real parameter list that is the same as that in the Variable Parameter array as the element of the array. An array does not need to be declared as a real parameter.
Main
{
Test ("yes", 34,389, 34 );
}
Test (string name, params int [] score)
{
}
11. Method Overloading is irrelevant to return values. The method name, parameter type, and number are related.
12. Differences between static and non-static
1) in non-static classes, you can either have instance members or static methods. Only static members can appear in static classes.
2) When calling an instance member, you need to use the object name. instance Member;
When calling static members, the class name and static method are required.
Summary: static members must be called by class names, and instance members must be called by objects.
Static functions can only access static members, but cannot access instance members.
You can use static members or instance members.
Only static members can appear in static classes. Static classes cannot be instantiated.
Usage:
1) if you want your class to be used as a "tool class", you can consider writing it as a static class.
2) Static classes are shared throughout the project. Static classes occupy memory.
GC Garbage Collection Garbage collector.
13. Constructor
Purpose: Help us initialize the object. constructor is a special method.
1) The constructor has no return value, and does not even have a void.
2) The constructor name must be the same as the class name.
14. new
1) Open up a space in the memory;
2) create objects in the opened space;
3) Call the constructor of the object to initialize the object.
The constructor must be public.
15. this
1) represents the object of the current class.
2) explicitly call the constructor of this class in the class: this
16. reference the class of another project in one project
1) first reference the project
2) reference the namespace of another project.
17. Value Type and reference type
Differences:
1. The value type and reference type are stored in memory differently.
2. The transfer method is different when the value type is passed and when the reference type is passed.
The value type is referred to as the value transfer, and the reference type is referred to as the reference transfer.


Value Type: int, double, char, bool, decimal, struct, enum
Reference Type: string, custom class
Storage:
The value type is stored in the memory stack.
The reference type is stored in the heap of the memory.
18. String
1) The unmutable character string. If the character string is re-assigned, the old value will not be deleted, but will be old in the stack.
Delete the address, and then assign a new address value to the string.
After the program ends, GC scans the entire memory. If some space does not point to the memory, it is destroyed immediately.
2) The string type can be considered as a read-only array of the char type.
Example:
String s = "abcde ";
// S [0] = 'B'; you cannot do this because it is read-only.
// If it is changed, the string must be converted first.
Char [] chs = s. ToCharArray ();
// Convert the character array to our string
S = new string (chs );
Console. WriteLine (s [0]);
19. StringBuilder
When a string is accumulated in a large number of cycles, a large amount of new memory space will be opened up, which is relatively slow.
Timing: Stopwatch Start (); Stop (); Stopwatch. Elapsed // record the total running time.
StringBuilder. Append (I); The Append method is used to accumulate.
StringBuilder saves a lot of time because it does not open up new space and then converts StringBuilder to String.
20. String Method
1), Length ()
2) ToUpper ()
3) ToLower ()
4) Equals (str1, StringComparision. OrdinalIgnoreCase): compares the two strings for consistency.
And case-insensitive.
5), Splite (character array, StringSplitOptions. RemoveEmptyEntries), delete the character array content, and do not return an empty array or null.
6), Contains ()
7), Replace (str1, str2)
8), string. Substring ();
9), string. StartWith ()/EndWith ()
10), string. indexof () returns the int type, returns the position where the string first appears
11), string. LastIndexof () the position where the last string appears.
12), string. trim () Remove all spaces in the string. String. trimStart ()/trimEnd ();
13), string. IsNullOrEmpty ()
14), string. Join (); can add the specified separator to the array for segmentation.

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.