Type and general language runtime: System. Object, general system. object

Source: Internet
Author: User

Type and general language runtime: System. Object, general system. object

CLR requires that each type ultimately inherit from the System. Object Type

1 // implicitly inherit Object2 class Employee {3... 4} 5 6 // display inherit Object7 class Employee: System. Object {8... 9}Type Definition (C #) Description

 

Public method of System. object

Equals: returns true if two objects have the same value.

GetHashCode: the hash code of the object value returned by the method. If an object is used as a key value of the hash list, the type of the object should overwrite GetHashCode ().

ToString: rewrite this method to return a string indicating the object status.

GetType: return an object instance of the Type inherited from the Type, which identifies the Type of the object to which the method belongs. The returned Type object can be used with the reflection class to obtain the Type metadata. (* The GetType method is a non-virtual method, which prevents a class from hiding its type by overwriting the method, thus undermining the type security)

 

System. object protected Methods

MemberwiseClone: Non-virtual method. It creates a new instance, sets its field to the same as the field of this object, and returns a reference to the newly created instance. For more information about this method, see

Finalize: Virtual method. When the Garbage Collector identifies an object as garbage collection, the garbage collector calls this method before the object memory is recycled. This method should be overwritten for the types of resources that need to be cleared during memory recovery.

 

CLR requires that all objects be created using the new operator (to generate the newobj IL command ). The following statement shows how to create an Employee object:

Employee e = new Employee ("ConstructorParaml ");

The following is the work performed by the new operator:

After new completes all these operations, it returns a reference pointing to the newly created object. In the preceding example, the reference is saved in variable e and its type is Employee.

There is no delete operator corresponding to the new operator. That is to say, in CLR, we cannot display the resources occupied by the released object. CLR introduces a garbage collection environment to automatically detect objects that are no longer in use or accessed and release their memory.

 

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.