English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C# Learning Notes1:
When the scope of variables conflicts, call instance variable: this.a, call class variable: className.a
Constants are always static, must be initialized, usually in uppercase format, the declaration keyword is const, such as const int NUNBE = 10;
C# basic predefined types are embedded in the .NET Framework structure (System), object is the base class;
integer type: System.SByte, System.Int16, System.Int32, System.Int64
signed8,16,32,64bit respectively represented as sbyte, short, int, long
unsigned8,16,32,64bit respectively represented as byte, ushort, uint, ulong
If an integer is explicitly declared with suffix U, L, UL, such as int, uint, long, ulong, choose the type according to the value range, the default is int
floating point type:32single precision float suffix F,64double precision double,128high precision decimal suffix M;
character type: char, such as 'A' enclosed in single quotes,4bit16number system of Unicode value (such as '\u0041), with data type conversion((char)65),16number system('\u0041), escape characters;
string type is a reference type, but strings are immutable, modifying one string will create a brand new string object, and the original string will not change;
string is similar to char, but it is enclosed in "", and can also be escaped, or use the prefix @"..." to treat all characters as their original meaning, i.e., no need to escape "\"
if (bool)
switch...case..break, each case must have a break; to end, or use goto case.. to activate case, or if the code after case is empty, jump to the next case;
In the switch statement, the order of the case clauses, even with the default clause, is not important, but no two cases can be the same, including constants with the same value but different names;
for (int i = 0; i < 100; i++{…}
use while (bool){...} when the number of repetitions is unknown, you can change the value of the bool variable within the clause to end the loop;
do{...}while (bool) at least execute1First, execute and then judge whether to loop;}
foreach(var x in arrays){...} iterates over each item in the collection, binding the value of each element to the variable x each time, but you cannot change the value of x. If you need to change the value of x, use a for loop;
goto Label1; The semicolon statement jumps directly to the line specified by the label, and the label is defined as Label1: ... The goto statement cannot jump to the loop body, cannot jump out of the scope of the class, and cannot exit the finally block after try...catch;
The break statement can be used to exit the for, foreach, while, do...while loop, switch statement;
The continue statement is similar to break, but it only 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 the value type or the reference type is passed as a method parameter, it is a copy on the stack (a copy of the value, a copy of the reference). The modification of the copy itself is only valid within the method and does not affect its original value. Note: the modification of the reference copy itself is only valid within the method, while the modification of the members of the reference copy will be saved outside the method. If you want to save the modification of the copy outside the method, you need to add the prefix ref or out, so that the reference of the parameter is passed to the method, not a copy;
The ref requires that the parameter has been initialized, while the out has no requirement, but it needs to be assigned within this method;
Optional parameters of the method: the optional parameters must be placed at the end of the definition and must be initialized. When calling, the parameter can be ignored and the default value of the optional parameter can be used, or a new value can be provided for it;
Method overloading (polymorphism): multiple methods with the same name but different parameters (number and type) can be defined, they cannot be distinguished only by the return value type, and they cannot be distinguished only by whether the parameters are ref or out;
If the optional parameters cannot achieve the purpose, the overloaded method can be defined to implement it;
This is the full content of the C# learning notes sorting_ basic grammar (must see) brought to you by the editor. I hope it will be helpful to everyone. Please support the cheerleading tutorial~