The System namespace contains the most commonly used. NET types. Corresponds to the first chapter of the preceding. NET base class. This can be understood as:. NET classes provide most of the functionality, and the C # language itself provides the rules.
Pseudo-code, haha, show tease code. Pseudo code.
Variables must be initialized to compile, otherwise error. In some cases, no initialization is shown, and the compiler defaults to 0 to compile.
Instantiating an object requires the use of the new keyword.
Type inference uses the var keyword. var i= 0; The system infers that I is a C # int type, which is the System.Int32 type of. Net.
A local variable declared in a for or similar statement exists in the body of the loop.
The variable J defined at the class level and the variable J defined in the subordinate method of the class, the compiler can recognize the same name, call the class level, need to use CLASS.J, the method is directly using J, the instance is in the form of THIS.J.
const int a= 100; This is a constant, no more changes. Must be initialized at the time of declaration.
C # is divided into value types and reference types, and most of the high-level languages are such. Value types are stored on the stack, and reference types are stored on the managed heap.
The reference type is set to NULL, which means that no objects are referenced.
The base type is defined as a value type, and other types are defined as reference types for best performance. If your defined type is defined as a value type, you should declare it as a struct.
C # has 15 predefined types, 13 are value types, and 2 are reference types (string object).
16-binary integer requires 0x prefix, long x = 0X12AB;
Double's precision is one-fold larger than float (15-bit).
The decimal type represents a higher precision floating-point number. The decimal type is not a base type, and there is a performance penalty for using that type when calculating.
The object type is the root type in C #, and all built-in types and user-defined types are derived from object.
String is a reference type, string differs from a generic reference type, changes a string, actually creates a completely new string, and the other reference does not modify the value.
Flow control Statements-conditional statements
1. If Else
2. If
3, if else if
4. Switch
Switch (Intergera)
{
Case 1:
Case 2:
Console.WriteLine ();
Default
}
Note that the value after the case must be a constant expression and is not allowed to be a variable.
If the case clause is empty, it jumps to the next one, so that multiple cases can be processed with a single statement. The value after the case cannot be the same.
Flow control Statement-Loop statement
1, for Loop. Before performing the next iteration, the test satisfies a condition, and the syntax is:
for (1-initializer; 2-condition; 4-iterator)
3-statement (s)
The sequence number on the order table is executed. 1234 of the order.
2, while loop. The while and for is the same as the predictive test cycle.
while (condition)
statement (s);
The while loop does not know the number of repetitions, which is different from for.
3, Do...while cycle. At least one loop body is executed.
Do
{
statement (s);
}while (condition);
4, foreach Loop. Iterates over each item in the collection.
foreach (int temp in arrayints)
{
Console.WriteLine (temp);
}
Note The Foreach Loop cannot change the value of the items in the collection (above temp). If you want to change the value, you should use a for loop.
Flow control Statement-Jump statement
C # provides a number of statements that can jump immediately to another line of code in the program, where the GOTO statement is introduced first.
1, goto statement.
Goto Lable1;
Console.Write ();
Lable1:
Console.WriteLine ();
The goto statement has two restrictions. You cannot jump to a block of code such as a for loop, or you cannot jump out of the scope of a class, and you cannot exit the finally block after the try catch block. In general, Goto is not necessary.
2, break statement. Exits the for,foreach,while,do while loop, which executes the statement following the loop.
3, continue statement. Similar to break, it must also be used in the for,foreach,while,do while loop. But he just exits the current iteration of the loop, not the exit loop.
4, return statement. Exits the method of the class, handing control over to the caller of the method. Returns must return a value if the method has a return type.
Enumeration
An enumeration is a user-defined integer type. Enumeration does not cause a performance penalty.
Name space
The general hierarchy is Company.Project.SystemSection. is an organization relationship, not a physical connection. Not the same as C + +.
Using can be quoted, all know.
namespace to name the alias. Use: Using alias = NamespaceName; call time using::, alias::classname.xxxx;
the Main () method is where C # begins execution. Must be a static method of a class or struct, and the return type must be int or void.
Multiple main methods, which can be compiled by/main. CSC doublemain.cs/main:wrox.mathexample
Command-line Arguments argsexample/a/b/c method name is public static int Main (string[] args)
The console can also use the format output {N,w},n is the parameter index and w is the width value. Console.WriteLine ("{0,4}+{1,4}:" I,j);
The console output can also use a format string. For example: Console.WriteLine ("{0,9:C2}", I), and if I is 940.23m, the $940.23 will be displayed. You can see the format string table in detail. There are several main cdefghpx. There are others.
The last console trick is the placeholder #, which is not read in the book, as follows:
Double d = 0.234;
Console.WriteLine ("{0:#.00}", D);
The result is. 23, because if there is no character in the position of the symbol #, ignore the symbol #, if there is a character in the position of 0, use this character instead of 0, otherwise it will display 0. This piece is not understood .
Comment Symbol/*/If it is in a string variable with double quotes, it will be treated as a normal string.
XML documents, written in code, create XML-formatted declarations that are useful. The description of the class, the meaning of the property and the parameter. The method of the system basically will have. We try to write it ourselves. It can also be output at compile time. Use the following statement:
Csc/t:library/doc:mathlibrary.xml MathLibrary.cs
C # Preprocessor directives, most of which are not used, require hands-on and detailed consideration of their usefulness. There are #undef #if #elif #else, #endif #warning #error #region #endregion, #line #pragma
Identifiers for C #
You can use Unicode characters such as \u005fidentifier, which is equivalent to _identifier.
C # Advanced Programming 9th Edition Chapter II core C # post-reading notes