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.