"C # Class Design Manual" reading

xiaoxiao2021-03-06  63

It should be said to know some of the basic concepts of some basic concepts, although the C # program has been written, but it has been turned over two days, and some things can be sucked. (The right as a summary of reading notes here ^ _ ^)

Several abbreviations:

CTS Common Type System Universal Type System

CLS Common Language Specification Public Language Specification

CLR Common Language Runtime Public Language Running

MSIL Microsoft Intermediate Language

GAC Global Assembly Cache Global Assembly Cache

Stack Stack Value Type

The hosted pile is similar to the pile of C, but does not consider it, it is called "hosting", managed

Space is much larger than the stack, but the accesses are slow

In the .NET environment, any type is both the value or the reference type, is an object system.Object

.NET has three value types: basic type, user-defined value type, struct, and enumeration type

C # lists String and Object as basic type, although they are reference types

Enumeration (bitmark) System.enum implements IFORMATTABLE

Reference Type: Class Type, Delegate (Type of Pointing Method, Security Pointer), array, string

No global variables and global functions in C #

Three must step:

Declaration commission;

2. Create a delegate object and bind it to a specific method;

3. Use the entrusted object to call this method

"C # Strings and Regular Expression Reference Manual" is more in-depth, there is time worth seeing.

Packing and unpacking

The boxed object contains a copy of the data in the value object. If the boxed object is modified, it does not affect the original value object.

Constants, compile time, change the corresponding assembly that needs to recompile the DLL in the DLL.

Static read-only variable, determine its value during operation

Database connection information, etc. should be placed in the configuration file, facing the deployment

Equals () .NET defines two forms of equivalents: reference equivalence, value equivalent

By default, system.Object.equals () test reference is equivalent, but Override is equivalent to the test value.

STACKFRAME and StackTrace in System.Diagnostics Access the stack framework and stack trace.

Method Type: Instance Method and Static Method.

REF is delivered by reference, method declarations and calls simultaneously using the REF keyword.

Output parameters, similar to REF is also passed by reference

Params Keyword Parameters must be the last parameter in the method declaration, and a large number of string operations should be used using System.Text.StringBuilder.

Try ... catch ... Finally

Properties and Operator JIT compilers can enable access to the attribute access than field access faster properties to quickly access object status.

Static property

Indexer container class, parent in the father and child relationship, a pair of multi-relations uses arraylist instead of array enhancements

Special way "operator"

Constructor and object lifecycle destroy object set object reference to null, and be careful not to have other references to the object, you can display destruction objects.

A large-scale destruction function in the application will have a negative impact on performance, handle the object destruction, and prefer the IDisposable interface, implement the Dispose method, execute in the Finalize destructor, but does not interrupt the garbage collection process.

Private constructor static constructor

Iclonable Clone Deep Copy MEMBERWISECOLONE Light Copy

Serialization and parallelization save object serialization, this technology is widely used in restoring applications, regularly acquires screenshot, save objects, and more. .NET Framework provides a wealth of XML serial model XSD.exe inferred XML mode, XML architecture / data type support utility

Events and entrusting event-based programming is the .NET Framework's cornerstone. The event mechanism in NET Framework uses the delegate (callback) event as a common method to release the event source object (object object) and the event receiver object ( The coupling between the subjects of the event notification).

Entrusted 3 steps similar to the method of the method in the application pointing to the object: 1 Declaring the delegate type 2 Create a delegate object, and bind the object binding method 3 using the delegate object to call the method

.NET Framework supports two types of commissioned average delegation: allowing an object to call a method multicast delegation: allowing a series of methods to be called on different objects to maintain a call object

Use the multicast commissioned step: 1 Define a delegate type 2 to write the same signature method as a delegate 3 to create a delegate object, bind it to the first method 4 that needs to be called, create another delegate object, bind to the next A method of calling the method 5 System.deLegate class, combined into an integrated multicast commission

Asynchronous entrustment can call the entrusted instance in the background thread: 1 Synchronous call, wait for the waiting method, the most common 2 asynchronous call, wait for the method to execute, endInvoke (), but before the method is executed, call 3 asynchronous Call, register a callback method, once the execution is completed, give notifications

The implementation of the event uses the event handler method of the delegate storage subscription, a typical OBServer design mode implements each event, you must specify the following two content: event name, the signature of the event (parameter list)

SYSTEM.EVENTHANDLER A built-in commissioned event cannot have a return type, only from the event source object to the one-way information flow of the event recipient object

Static incidents are rare, relative to general events

Defining the way you register, you don't need to define customized registration methods in most cases, but this technology can make your code simpler and fast. In Framework, most controls use customized registration methods.

Base classes and subclasses cannot reference the same entrusted inheritance and polymorphisms support, polymorphisms are supported by inheritance, regarding a type of object as a polymorphism of another type of instance

The base class is defined as Virtual. The derived class can rewrite the operation mark as the non-virtual method. It cannot be rewritten. The operation declaration is Virtual, and the implementation can be rewritten to abstract, and the implementation must be rewritten.

The class inherits from the System.Object structure inherits from System.ValeType, inherits from System.Object to the interface type it implements it, carefully, causing any objects that the interface is not supported by the reference type.

Code organization and metadata

Sharing assembly global assembly Cache Global Assembly Cache (GAC)

The minimum unit of assembly reusable

Metadata provides all the information required for the loading type and calling method during operation, metadata is the basis of metadata, which is also a fundamental thing in many systems. Understand this thing can be more in-depth understanding of an architecture.

View metadata The simplest method uses ILDASM.EXE / ADV or / Advancel option

The .NET module is a portable, executable (PE) format file

Only data module SDK contains a tool Assembly Linker (al.exe) using this tool to link these non-MISL modules to the program set to compile the file into modules, you must use the C # .NET command line compiler cannot use Visual Studio .NET Because it is always created, the program set, for example: csc / target: module csmod.cs csmod.netModule * .NetModule is a .NET module adding module to the assembly list: CSC / AddModule: csmod.netModule / AddModule: VBMOD. NetModule mainmod.cs

The program deployment deployment single assembly application is relatively simple and deployed directly with XCOPY. Private assembly deployment application is not complicated, put the needed program collection in the same folder or notify the CLR in what location lookup assembly

Deploying Sharing Settings Add to GAC Global Program Cache But Microsoft does not recommend application and GAC interdependent, try to use application private assembly deployment mode

Using the public-private key pair compiler to create a strong name to create a strong name, the corresponding public key is written in the assembly list Sn (STRONG NAME) SN / K *. SNKMSDN lookup "Keys Crytography" lookup Corresponding content Publickey longer digital public key token public key token SN / T * .snk

Install the shared assembly to the GACUTIL -I * .DLL of the GAC requires administrator privileges or finds .NET Framework Configuration in the control panel management tool.

1. Windows Forms has a commonly used property that usually not pays attention to: AcceptButton: Set the function of that button in response to the ENTER button in the table. The default value None CancelButton: Sets the function of the button to the corresponding reaction in the form of the form. Default value None

2. FORM When the form is called, the order is triggered by the event and method: load -> gotfocus -> activated -> closing -> closed -> deactivate -> lostfocus -> Dispose show method implicit call load, so if one The form even if it is not loaded if it is not loaded, the table will be loaded directly into the table. 3. When you need to run some code when you are displayed or hidden, put in Activated and Deactivate better than Gotfocus and Lostfocus events. 4. Receive a request from a Close, the form first run the code in the CLOSIG event, then the CLOSED code, so the data valid check is in the closing. 5. Hide method, even if there is no form to LOAD to memory, you will also display the form LOAD to memory when the HIDE is called, but not.

转载请注明原文地址:https://www.9cbs.com/read-117239.html

New Post(0)