The basic method of object default in. Net

Source: Internet
Author: User

In. NET, the base class for all built-in types is System.Object. What is included in the System.Object class is often the subject of the interview. System.Object contains 8 methods, including Finalize, with 3 virtual methods: The Equals, GetHashCode, and ToString methods. When designing a type, you might consider overriding the Equals method when you need to make a content comparison of the type object, and only consider overriding the GetHashCode method when the type will be used as the container's key value, and most types should consider overriding the ToString method. The following is a list of System.Object methods:

Public instance methods Brief description
Virtual bool Equals (object obj) Determines whether two objects are equal, Equals returns True, and is not equal returns false
Virtual bool GetHashCode () Returns a hash code for this object
Type GetType ()

Returns the type of the current object

Virtual string ToString () Returns a string that can represent the current object, in which the method returns the full name of the current object type System.Object
public static methods Brief description
BOOL Equals (Object Obja,object OBJB) Determines whether two objects are equal, Equals returns True, and is not equal returns false
BOOL ReferenceEquals (Object Obja,object OBJB) Compares references to two objects for equality, returns true for equality, and returns false for equality
Protected instance method Brief description
Object MemberwiseClone () Shallow copy the current object instance and returns a reference to the copied object
Finalize . Net-destructor method

The basic method of object default in. Net

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.