C # Modifier

Source: Internet
Author: User

C # Modifier

Modifiers are used to restrict the declaration of types and type members. modifiers in C # can be divided into four parts by function: attribute modifier, access modifier, class modifier and member modifier. Property modifier: [Serializable]: blocks objects to remote servers by value. When an object is sent by value, a copy of the object is created and serialized to the server. Any method call to this object is performed on the server. [STAThread]: indicates a Single-Threaded Apartment Single-Threaded suite. It is a thread model (the thread mode is used to process components in a multi-Threaded environment in parallel and in mutual mode ), in the STAThread mode, cross-thread interface transfer must be scheduled. Direct transfer without scheduling will certainly fail! The interface in MTA or FreeThread mode can be directly transmitted without scheduling. This type of scheduling has a significant impact on performance in a specific environment (hundreds of times worse ). For example, VB only supports the STAThread mode. Components in FreeThread mode are as slow as cross-process components! Thread mode is an extremely important concept in Microsoft's COM base. Be sure to thoroughly understand! [MTAThread]: it is the meaning of MultiThreaded Apartment multi-threaded suite. It is also a thread model. Access modifier: public: unrestricted access. Private: only the class containing this member can be accessed. Internal: only the current project can be accessed. Protected cannot be displayed after dll is referenced: only classes containing this member and derived classes can be accessed. After using this modifier, the method must inherit the class to which this method belongs. Can only be called using a derived class
For example:
Class BaseTest {public int a = 10; protected int B = 2;} class ChildTest: BaseTest {int c; int d; static void Main (string [] args) {BaseTest basetest = new BaseTest (); ChildTest childTest = new ChildTest (); Console. writeLine (childTest. b) ;}} class modifier: abstract class. Indicates that a class can only be used as the base class of other classes. Newsealed cannot be instantiated: Seal class. Indicates that a class cannot be inherited. Naturally, the sealed class cannot be an abstract class at the same time, because the abstract always wants to be inherited. Member modifier: abstract: indicates that this method or attribute is not implemented. The derived class that inherits the class must override this method sealed: sealed method. This prevents override (overload) of the method in the derived class ). Not every member method of the class can be used as a sealing method. The virtual method of the base class must be overloaded to provide specific implementation methods. Therefore, in method declaration, the sealed modifier is always used together with the override modifier. Delegate: delegate. Defines a function pointer. The event driver in C # is based on delegate + event. Const: the value of the specified member cannot be modified only. Event: declare an event. Extern: indicates that the method is implemented externally. Override: rewrite. The new implementation of the inherited members of the base class. Readonly: indicates that a domain can only be assigned values when declared and inside the same class. Static: indicates that a member belongs to the type rather than a specific object. That is, it can be used after definition without being instantiated. Virtual: indicates that the implementation of a method or accessor can be overwritten in the inheritance class. New: hides the specified base class member in the derived class to implement the rewrite function. To hide a member of an inherited class, declare the member with the same name in the derived class and modify it with the new modifier.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.