C study notes sorting _ basic grammar such as variables of must see articles

  • 2021-11-10 10:29:32
  • OfStack

C # Study Note 1:

Invoke instance variable: this. a, call class variable: Class name. a

Constants are always static and must be initialized, 1 in all-uppercase format, declaring the key as const, such as const int NUNBE = 10;

The basic predefined type of C # is built into the. NET Framework structure (System), and object is the base class;

Integer types: System. SByte, System. Int16, System. Int32, System. Int64

Signed 8-bit, 16-bit, 32-bit and 64-bit are represented as sbyte, short, int and long respectively

The unsigned 8-bit, 16-bit, 32-bit and 64-bit are represented as byte, ushort, uint and ulong, respectively

If an integer is int, uint, long, ulong explicitly declared with the suffixes U, L, UL, select the type according to the numeric range, and the default is int

Floating point type: 32-bit single-precision float suffix F, 64-bit double-precision double, 128-bit high-precision decimal suffix M;

Character types: char, such as' A 'enclosed in single quotation marks, Unicode values with 4 digits in hexadecimal (such as'\ u0041 '), with data type conversion ((char) 65), hexadecimal numbers ('\ u0041 '), escape characters;

The string type is a reference type, but the string is immutable. Modifying one of the strings will create a brand-new string object without changing the original string;

string is similar to char, but it is enclosed by "", which can also be escaped, or prefixed with @ "...", and all the characters contained are regarded as their original meanings, that is, there is no need to escape "\";

if (bool)

switch... case... break, each case must have break; To end, or activate case with goto case..., or jump to the next case if the subcode after case is empty;

In switch statement, the order between case clauses or even with default clauses is irrelevant, but no two case can be the same, including constants with the same value and different names;

for (int i = 0; i < 100; i + +) {…}

while (bool) {...}, while is used when the number of repeated executions is unknown, and the value of the bool variable can be changed within the clause to end the loop;

do {...} while (bool) is executed at least once, and then it is judged whether it is circular or not;

foreach (var x in arrays) {...}, every item in the iteration set, binds the value of the element to the variable x every time, but the value of x cannot be changed. If you need to change the value of x, apply for loop;

goto Label1; Statement directly jumps to the line specified by the tag, and the tag defines Label1:..., goto statement cannot jump into the loop body, jump out of the scope of class, and exit finally after try... catch block;

break statement can be used to exit for, foreach, while, do... while loop, switch statement;

The continue statement is similar to break, but it simply exits the current iteration of the loop and executes the next iteration;

The return statement is used to exit the method of the class and return control to the caller of the method;

By default, Whether it is a value type, a reference type as a parameter to a method, What is passed is its copy on the stack (copy of value, copy of reference). The modification of the copy by the method is only valid inside the method and does not affect its original value. Note: Modifying the reference copy itself is only valid inside the method, while the modification of the members of the reference copy will be saved outside the method; To save changes to the copy outside of the method, prefix ref or out so that the method is passed a reference to the parameter, not the copy;

ref requires that the parameter has been initialized, while out does not require it, but it needs to be assigned in this method;

Optional parameter of method: The optional parameter should be put last when defining, and must be initialized. When calling, you can ignore the parameter and use the default value of the optional parameter, or provide it with a new value;

Method overloading (polypeptide): You can define multiple methods with the same name, different parameter numbers and different parameter types, and you can't distinguish them only according to the return value type, and you can't distinguish them only according to whether the parameters are ref or out;

If you can't achieve your goal with optional parameters, you can do it by defining overloaded methods;


Related articles: