NET Fundamentals (1): Type basics

Source: Internet
Author: User

All types are derived from System.Object, and the ' runtime ' requires that each type be from system. The object class derives, that is, the following two type definitions are exactly the same:

Implicitly derived words objectclass employee{do   something ...} An explicit derivation of the word Object class employee:system.object{do   something ...}

Since all types ultimately derive from System.Object, each object of each type guarantees a basic set of methods, and System.Object provides a common instance approach:

1, Equals: Returns True if two objects have the same value.

2, GetHashCode: Returns the hash of the value of the object.

3. ToString: The full name of the default return type (This.gettype (). FullName).

4. GetType: Returns an instance of type derived from one of the types that indicates what type of object is called GetType. The returned type object can mate with the reflection class to get metadata information about the type of the object.

The CLR requires that all objects be created with the new keyword, and the following code shows how to create an Employee object:

Employee E = new Employee ("Constructorparameter");

Here's what the new operator does

1. The calculation type and all of its base types (until System.Object, although he does not define his own instance fields) require a number of additional members for each object on the heap, including the type Object Poniter and Sync Block index. The CLR takes advantage of these members to manage objects, and the extra member's bytes are counted in the size of the member.

2. Allocate the number of bytes required by the class from the managed heap to classify the object's memory and allocate all bytes to zero.

3. Initialize the object's "type Object pointer" and "Synchronize index block" members.

4. Invokes the instance constructor of the type, passing the argument specified in the new call.

New returns a reference (pointer) to the new object after all of these operations have been performed.

Note: There is no delete operator for the new operator: In other words, there is no way to explicitly release the memory allocated to the object, and the CLR uses a garbage collection mechanism (GC) to automatically detect that an object is no longer being used and accessed, and frees the object's memory.

NET Fundamentals (1): Type basics

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.