It should be said to understand some of the basic concepts of a very good book, although the writing of such a long period of C # program, but two days, but also feel something to learn. (right here as a summary of reading notes ^_^)
Several abbreviation terms:
CTS Common type System common types systems
CLS Common Language Specification Common Language Specification
CLR Common Language Runtime Common Language runtime
MSIL Microsoft Intermediate Language
GAC Global Assembly Cache
Stack stack value types are used
The managed heap is similar to the C heap, but does not consider the release, so called "managed", Managed
The space is much larger than the stack, but the access speed is slow
. NET environment, any type, whether it is a value or a reference type, is an object System.Object
. NET has 3 types of values: base type, user-defined value type, struct and enum type
C # also lists string and object as basic types, although they are both reference types
Enumeration (bit mark) System.Enum implements the IFormattable
Reference type: class type, delegate (pointer to method type, security pointer), array, string
There are no global variables and global functions in C #
3 mandatory steps for a delegate:
1. Declaration of Entrustment;
2. Create a delegate object and bind it to a specific method;
3. Using the delegate object, call this method
The C # string and regular expression reference manual is a more in-depth approach to string processing, with time worth seeing.
Boxing and unboxing
The boxed object contains a copy of the data in the value object, and if the boxed object is modified, the original value object is not affected.
constants, which are determined at compile time, change the corresponding assemblies in the DLL that need to be recompiled to call the DLL.
Static read-only variable that determines its value during run time
Database connection information, etc. should be placed in the configuration file for deployment
Equals (). NET defines two forms of equivalence: reference equivalence, value equivalence
By default, the System.Object.Equals () test reference is equivalent, but it can be override to make its test value equivalent.
System.Diagnostics in the StackFrame and StackTrace access stack frame and stack trace.
Method Type: Instance method and static method.
Ref is passed by reference, and the method declaration and invocation use the REF keyword.
Output parameters, similar to ref out are also passed by reference
The params keyword parameter array must be the last parameter in the method declaration, and a large number of string operations should use the
System.Text.StringBuilder
Try ... Catch... Finally
Properties and operators
The JIT compiler can make property access faster than field access
Properties are a technique for quickly accessing the state of an object.
Static properties
Indexer
Container class, parent in parent-child relationship, one-to-many relationship
Using ArrayList instead of array enhancements
Special method for "operator"
Constructors and object life cycles
Destroying objects
Set the object reference to NULL, and note that no more references to the object are available to display the destroyed object.
A large number of destructors in the application have a negative impact on performance, processing object destruction, and using the preferred method
IDisposable interface, implementing the Dispose method, executed with the Finalize destructor method, but without interrupting garbage collection
Process.
Private constructors
Static constructors
iclonable Clone deep copy memberwisecolone shallow copy
Serialization and Parallelization
This technique is widely used to restore the state of an application, periodically capturing screenshots, saving objects, and so on.
The. NET Framework provides a rich XML serialization model
Xsd.exe inference XML schemas, XML Schema/data type support utilities
Events and Delegates
Event-based programming is the cornerstone of the. NET Framework
The event mechanism in the. NET framework uses a delegate (callback)
Events act as a common way to disassociate the event source object (the object that generated the event) from the event sink object (the object that receives the event notification).
A delegate is similar to a pointer in an application that points to a method in an object
3 steps:
1 declaring delegate types
2 creates a delegate object and binds the object to the specified method
3 using a delegate object to invoke a method
The. NET framework supports two types of delegates
Unicast delegate: Allows a method to be called on an object
Multicast delegates: Allows a series of methods to be called on different objects to maintain a calling object
To use a multicast delegate:
1 Defining a delegate type
2 writing a delegate with the same signature method
3 Create a Delegate object, bind it to the first method that needs to be called through a delegate
4 Create another delegate object that binds to the next method that needs to be called
5 The Combine method of the System.Delegate class, combined into an integrated multicast delegate
Methods that an asynchronous delegate can invoke in a background thread
Three ways to invoke a delegate instance:
1 synchronous calls, wait for method execution, most common
2 asynchronous call, wait for the method to finish executing, EndInvoke (), but call before the method finishes executing
3 Asynchronous call, register a callback method, once execution is complete, give notification
Event implementation using the event-handling method of the delegate store subscription, a typical implementation of the observer design pattern
For each event, you must specify the following two items: event name, signature of event (parameter list)
System.EventHandler a built-in delegate
Event cannot have return type, only one-way flow from event source object to event receiver object
Static events are less visible, relative to general events
Define your own method of registration
In most cases, you don't need to define a custom registration method, but this technique makes the code the most concise and fast.
In the framework, most controls use a custom registration method.
Base class and subclass cannot reference the same delegate
Inheritance and polymorphism are supported by all object-oriented languages, polymorphism is supported by inheritance, and one type of object is treated as the polymorphism of another type of instance
The base class is defined as virtual, and the derived class can override the operation of the base class
Methods that are marked as non-virtual cannot be overridden
Operation declared as virtual, you can override the implementation
The operation is declared abstract, and the implementation must be overridden
class inherits from System.Object
Structs inherit from System.ValueType, inherit from System.Object into the interface type it implements, be careful with reference types instead of types, and cannot invoke any objects that the interface does not support.
Code organization and Meta data
Shared Assemblies Global Assembly Cache Assembly cache (GAC)
The smallest unit that the assembly can reuse
Metadata provides the common language runtime with all the information it needs to load types and invoke methods during run time
Metadata is the foundation of meta-programming and is fundamental in many systems, and understanding this can be a more in-depth understanding of a schema
The simplest way to view metadata using the ILDASM.EXE/ADV or/advancel option
. NET module is a portable, executable (PE) format file
Only the Data Module SDK contains a tool assembly Linker (AL.exe)
Use this tool to link these non-MISL modules to an assembly
To compile the file into a module, you must use C #. NET command-line compiler
You cannot use visual Studio. NET because it always creates a single, assembly
Example: Csc/target:module csMod.cs csmod.netmodule
*.netmodule is a. NET module
Add the module to the assembly manifest:
Csc/addmodule:csmod.netmodule/addmodule:vbmod.netmodule MainMod.cs
Program Deployment
Deploying single assembly applications is straightforward and is deployed directly with Xcopy.
Private assembly deployment applications are also not complex, put the required program collections in the same folder, or use application configuration files to notify the CLR where to look for assemblies
To deploy a shared assembly
Add to GAC Global Assembly cache
However, Microsoft does not recommend that applications are interdependent with the GAC and should be deployed as far as possible with application-private assemblies
Use public-private key pairs to create strong names for assemblies
During compilation, the compiler uses the private key to write the corresponding public key to the assembly manifest
SN (strong Name) sn/k *.snk
Find "Keys crytography" in MSDN to find the appropriate content
PublicKey a longer number
Public Key Token Token
sn/t *.snk
To install a shared assembly into the GAC
Gacutil-i *.dll requires Administrator privileges
Or find the. NET FrameWork Configuration in the Management tool in Control Panel
1. Several common properties that Windows forms usually do not notice:
AcceptButton: Set in the table click Live State, press ENTER to correspond to the function of that button. Default Value None
CancelButton: Set the function of the button in the table click Live State, the ESC key corresponds to the response. Default Value None
2. The order in which events and methods are triggered when form method show is called:
Closing, Closed, Deactivate, Activated, GotFocus, Load, LostFocus
The Show method implicitly calls load, so if a form is not loaded, calling the Show method will also load the form directly.
3. When you need to run some code when the form is displayed or hidden, place it in activated and deactivate than the GotFocus and LostFocus events.
4. Upon receipt of the close request, the form runs the code in the closing event and then closed the code, so the data validation is good in closing.
5. Hide method, even if no form is not load into memory, the form is also load into memory when hide is called, but not displayed.
Basic knowledge of C # class design Handbook