Structural body

xiaoxiao2021-03-06  43

The structure may seem like a class, but there are some important differences, which should be paid attention to. First, the class is a reference type, and the structure is a value type. When you call the New (New) operator on the class, it will allocate on the heap. However, when instantiated, the structure will be created on the stack. In view of this reason, the structure is transmitted to the method, and the structure will pass values, not as reference delivery.

The structure can declare the constructor, but they must have parameters. The default (non-parameter) constructor of the declaration structure is wrong.

The structure is created in the stack, and you are not a reference to the structure, but the direct processing structure. Whenever a type that will be used frequently, and most cases this type is just some data, the structure may be the best choice.

Public struct structtest {public int x;} ... private structtest aaa; // This time the structure has been created in the stack ...

Performance can be enhanced by smartly using the structure.

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

New Post(0)