C # Based on these, have you seen? (a)-----who has just begun to learn to use

Source: Internet
Author: User
Tags uppercase letter

1, gaze (do not write the gaze is rogue, from nonsense name blind)
'///' is generally used for eye function. Gaze class.
2. Hotkey
Ctrl+k+d (cannot be aligned with syntax errors)
Ctrl+j (High-speed pop-up can only hint)
The Shift+end,shift+home key starts at the beginning of the line, from the end of the line to the beginning.
Ctrl+k+c Gaze ctrl+k+u Cancel Gaze
ALT+SHIFT+F10 Open the description reference space.
F1 go to MSDN
F12 go To Definition

3. Data type
Decimal money=5000m. (Money type)
String and string are the same in C #. String is a common type of. NET platform. String is a C # secondary school. All two of them are mapped to the System.class class.
4. Naming specification
* 1, Camel naming specification (more for variable naming): first word first letter lowercase, the rest of the first letter of the word uppercase.
* 2, Pascal naming specification (more for class or method naming): All words are capitalized in the first letter.


5. Placeholder
To use: Dig a hole first. Fill a hole again.


Console.WriteLine (".. {0},... {1},... {2} ", N1,N2,N3);
6. Escape character
\ n: newline, but not in Windows system, just know \ r \ n.
\ ": Output half-width index
\t:tab Key (Typesetting)
\b: Backspace. The end-to-end placement is invalid. Just a backspace.
@:1, cancels the escape function in the string.

2. Preserve the original format output.


7. Enumeration
===== enumeration and int and string conversions = = =
@1, enum type default ability to convert to int type enum type is compatible with int
@2, enum type is converted to string, with ToString ().
Enumeration type Object name = (enumeration type) Enum.parse (typeof (enumeration name), string s);
8. Properties
Use method: The property begins with an uppercase letter. The field starts with lowercase letters.


Class Person
{
private int age;

public int Age
{
Set
{
This.age=value;
}
Get
{
return this.age;
}


}
9. There is no global variable in C # to say that only static fields can be used to simulate global variables.


10. Three major references in C #
1) out of the parameters:
If you return multiple values of the same type in a method, consider returning an array.


However, it is necessary to return multiple values of different types.

Out can return more than one value or multiple different values.
in fact, the out function is to return multiple values of the called function. is opposite to the general return direction.
note: The out definition variable must be assigned a value in the called function.
2) ref arguments:
you can change a variable into a method. After the change is complete. The changed values are then taken out of the method.


main ()
{
int s=10.
Test (ref s).


}
Test (ref S1)
Span style= "White-space:pre" > {
s1+=3
}
3) parame parameters:
variable parameters
treats a type that is consistent with the type in the variable parameter array as an element of the array in the argument list. It is not possible to declare an array without an actual participation.


Main
{
Test ("for".) 34,389. 34);
}
Test (string name. Params int[] score)
{
}
11, the overloads of the method and the return value are independent. As to the method name, the type of participation, the number of related.
12. Static and non-static differences
1), in a non-static class. You can have both instance members and static methods.

Only static members can appear in static classes.
2), when invoking an instance member. You need to use the object name. Instance members;
When a static member is called, the class name is required. static method.


Summary: Static members must be called using the class name, and instance members are invoked with the object.
Static functions are only able to access static members and do not agree to access instance members.
Instance methods can use both static members. You can also use instance members.
Only static members can appear in static classes. A static class cannot be instantiated.
Use:
1), assuming that you want your class to be used as a "tool class", this can be considered as a static class
2), static class in the entire project resource sharing.

Static classes are memory-occupied.
GC garbage Collection garbage collector.
13. Constructor function
Function: Help us initialize the object, the constructor is a special method.
1) The constructor does not return a value. Not even void.
2) The name of the constructor must be the same as the class name.
14. New
1) Open a space in memory;
2) Create objects in the space to be opened again;
3) invokes the object's constructor to initialize the object.


The constructor must be public.


15, this
1) Represents the object of the current class.


2) The constructor for this class is explicitly called in the class  : This
16, a class that references a project in one project
1), referring to the project
2), and a reference to the namespace of the project.
17, value type and reference type
difference:
1, Value types and reference types are different in memory where they are stored
2, which is passed differently when passing value types and passing reference types.
value types we call value passing, reference types we call reference passing.


value type: int, double, char, bool, decimal, struct, enum
reference type: string, self-defined class
store:
value types are stored in the stack of memory. The
reference type is stored in the heap of memory.
18, String
1"), the character string is immutable, assuming that the string is assigned again, the old value is not deleted, but the old
address deleted. Once again, give the string a new address value.


When the program finishes, the GC scans the entire memory. If you find that some space is not pointing, destroy it immediately.
2), the ability to treat the string type as a mere reading group of type Char.


Cases:
String s= "ABCDE";
s[0]= ' B '; Because it's just read.
If you change the word, you first need to convert the string.


char []chs=s.tochararray ();
Convert a character array to our string
S=new string (CHS);
Console.WriteLine (S[0]);
19, StringBuilder
When a large number of loops accumulate in a string, a lot of new memory space is opened. More slowly.
Chronograph: Stopwatch Start ();  Stop (); stopwatch.elapsed//Record the total time of execution.
Stringbuilder.append (i); Append method to accumulate.


StringBuilder can save very much time. The reason is that it does not open up new space. Then convert StringBuilder to String
20, String method
1), Length ()
2), ToUpper ()
3), ToLower ()
4) Equals (str1. Stringcomparision.ordinalignorecase): Two strings are consistent
5), Splite (character array. stringsplitoptions.removeemptyentries), the contents of the character array are deleted, and no empty arrays and null are returned.
6), Contains ()
7), Replace (str1 , str2)
8), string. Substring ();
9), String. Startwith ()/endwith ()
10), String.IndexOf () returns the int type, returning the position where the string first appears
Span style= "White-space:pre" > 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 (); it can be added to the array delimiter to specify the grinding.

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

C # Based on these, have you seen? (a)-----who has just begun to learn to use

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.