1. namespace usage
1.1 The namespace is a logical division of the Code in. net. It is similar to the package in Java. However, the namespace does not correspond to the physical file path of the package.
1.2 The namespace is extracted using the using keyword. For more usage of using, refer to using of anytao.
1.3 nested namespace usage and alias
Namespace levelone
{
Using lT = leveltwo; // defines the alias
Public class leveloneclass
{
Static string levelonename = "onename ";
Levelone. leveltwo. leveltwoclass twoclass1; // apply it through full path
Leveltwo. leveltwoclass twoclass2; // because leveltwo is inside levelone, you can directly reference the leveltwo path
Lt. leveltwoclass twoclass3; // alias reference
}
Namespace leveltwo
{
Using Lo = levelone; // defines the alias
Using loc = leveltwoclass;
Public class leveltwoclass
{
Static string leveltwoname = "twoname ";
Levelone. leveloneclass oneclass1; // access through full path
Leveloneclass oneclass2; // leveloneclass is on the outer layer of leveltwo and can be accessed directly.
Lo. leveloneclass oneclass3; // access by alias
Loc loc = new LOC (); // use the class by alias
}
}
}
2. Operator priority
The priority is higher than the following:
++, -- (Prefix); +,-(one dollar)
*,/, %
+ ,-
=, * =,/=, % =, + =,-=
++, -- (Suffix)
3. Cyclic interruption
C # provides four commands:
1. Break --- terminate the cycle immediately
2. Continue --- stop the current loop immediately and continue executing the next loop
3. Goto --- jump out of the loop to the known mark (goto is not recommended)
4. Return --- jump out of the loop and Its contained Functions
4.% operators and/Operators
%: Return the remainder operator, such as 5% 2 = 1
/: Division operation, such as 5% 2 = 2
5. Common types and type conversion
1.. Net Type branch type and reference type
2. Value Type: simple type, struct, enumeration; reference type: String, class, interface, etc.
3. Simple Type: numeric, Boolean, and character type
4. Value Type: integer and floating point. Integer types include: byte (non-negative), short, Int, long, And sbyte (including negative numbers), ushort, uint, and ulong
The above types are. net has the following alias corresponding to it: system. byte, system. int16, system. int32, system. int64 and system. sbyte, system. uint16, system. uint32, system. uint64
Float types include float, double, and decimal. Their aliases are: system. Single, system. Double, system. decimal.
5. boolean and character types: bool (system. Boolean), char (system. Char, a Unicode character, two bytes)
6. The string type is a reference type, but its usage process is like a value type.
7. Conversion between character types and numeric types
Char CH = 'a ';
Ushort B = CH;
Console. writeline ("ch: {0}", CH );
Console. writeline ("B: {0}", B );
8. escape characters
\ A: Warning
\ R: press Enter: console. Write ("rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr \ rkkkkkkkkkkk ");
Result: kkkkkkkkkkkkkkrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
\ N: line feed:
9. @ effect on strings
@ + String: Ignore escape characters in the string, such as @ "C: \ window \ a.txt", which is equivalent to "C: \ window \ a.txt"
You can even use string STR = @"
BCD "; space and carriage return are directly part of the string; otherwise, the carriage return must use/R/N;
10. type conversion: implicit and explicit conversions.
Implicit conversion: Use the = Operator to directly assign a variable of Small-range type to a large-range variable, or assign a subclass variable to the parent variable. The conversion operation is completed by the compiler.
Display conversion: If you want to convert a large range of variables to a small range of variables, or assign the parent class to a subclass, or perform conversion of different types (such as inttostring or stringtoint)
Animal animal = new animal ();
Bird = new bird ();
Animal = bird; // implicit conversion
Bird = (BIRD) animal; // display Conversion
Byte B = 7;
Int myi = 33333;
B = (byte) myi; // display conversion ---------- this display conversion involves two keywords: checked and unchecked.
B = checked (byte) myi); when the conversion overflows, an exception is thrown and the overflow detection is performed. The unchecked switch is used by default.
Myi = B; // implicit conversion
B = checked (byte) myi );
String STR = "100 ";
Myi = convert. toint32 (STR); // display Conversion
11. Enumeration
1. enumeration is of the int type by default, but can be any numeric type, including byte, sbyte, short, ushort .....
Defines an enumeration of the byte type. The enumerated values can be the same.
Enum typename: byte
{
Value1 = 1,
Value2 = 1,
Value3 = 3,
Value4 = 1
}
2. Several types of enumeration conversion operations: byte, Enum, string
Typename myenum = typename. value1;
String myenumstr = myenum. tostring (); // enumtostring
Byte myenumbyte = (byte) myenum; // enumtobyte
Typename myenum2 = (typename) enum. parse (typeof (typename), "value2"); // stringtoenum
12. Differences between ref, out, And Params
Ref: a parameter of the reference type. Generally, the parameter used for method calling is a value type. When the ref keyword is used as the parameter prefix, the parameter reference is passed, the modifications are directly reflected in the real parameters. Before using the reference type parameter, you must first initialize it.
Out: the output type parameter is also a reference type, but the difference with ref is that initialization is not required before use. Multiple output parameters are allowed. In this way, the out method is useful when multiple return values are required.
For ref and out parameters, if only the two keywords are used for differentiation, they cannot constitute a method overload.
Params: array type parameter. Only one Params keyword can be used for a method, and other keywords cannot be used together.