A quick overview of C##, maybe compare it with C++? review

C#

Serialization and deserialization

Serialization: Cache Object as data, refer to the game archive

Deserialization: the reverse process of serialization, refer to game file reading

  1. Save the object locally and restore the object the next time you run the program.

  2. Transfer the object to another terminal on the network, and then restore the object on this terminal.

  3. Copy it to the system clipboard, and then use the shortcut key Ctrl+V to restore this object.

[XmlIgnore] can indicate that a public member does not participate in the serialization and deserialization process.

The following requirements are required to perform serialization:

— The class must have a public no-argument constructor; public MyClass()

— Fields and properties to be deserialized must be public; public

— Does not contain circular references;

— Does not contain non-serializable member variables;

Delegations and events

Delegation can increase the scalability of the program and reduce the logical judgment of if...else;

Use += to bind a method to a delegate, -= to unbind.

  1. Delegate is a type
  2. A delegate is a linked list of functions of the same type as the return value
  3. The delegate uses the three symbols +=, =, and -= to operate the functions in the linked list.
  4. Calling a delegate will call all functions in the delegate list in sequence.
  5. The delegate return value defaults to the last added function return value

1. The essence of delegation is a sealed class, which inherits MulticastDelegate (multicast delegation)

2. The delegate constructor has two parameters, one of type is IntPtr, which is used to receive methods, as shown below:

img

3. It can be called synchronously (Invoke) or asynchronously (BeginInvoke, EndInvoke)

Note:

1. Multicast delegation: A delegate can represent multiple methods with the same signature. When the delegate is called, these methods will be executed in sequence.

2. When IntPtr represents a window, it is called a "handle", and when it represents a method, it is called a "pointer".

3. Asynchronous call: A thread will be generated and executed asynchronously

Events are a special kind of delegation

First, make it clear that the keyword event is used when instantiating the delegate rather than when defining the delegate.

Definition and use of delegation

        delegate void func();
        static func l;

Definition and use of events

        delegate void func();
        static event func l;

Events need to be combined with classes. Only the class that defines the event can call the event. Delegation links and cancels or triggers functions and can be used freely. Events are restricted to be triggered only by the class at which they were declared.

c# value types and reference types

The two storage methods are different, so there is a difference in copy (deep copy and shallow copy)

Common deep copy methods:

. Events are restricted to be triggered only by the class at which they were declared.

c# value types and reference types

The two storage methods are different, so there is a difference in copy (deep copy and shallow copy)

Common deep copy methods:

Reflection, serialization and deserialization (binary\XML)

Guess you like

Origin blog.csdn.net/weixin_43925768/article/details/133272350