. Net has four C # judgment functions? Many people may doubt this title. In fact, this is the case.. Net provides ReferenceEquals, static Equals, specific Equals, = operator, and other functions. However, there is a slight relationship between the four functions. Changing the implementation of one function affects the operation results of other functions.
The first thing we need to talk about is the Object. ReferenceEquals and Object. Equals static functions. For them, they do not need to be rewritten because they have completed the operations they need to do. For the static function Object. ReferenceEquals, the function situation is as follows:
- public static bool ReferenceEquals object left, object right );
This function is used to determine whether two referenced objects point to the same address. With this description, the scope of use is determined, that is, you can only operate on the reference type. For any value type data operation, even if it is identified by itself, false is returned. this is mainly because the value type data needs to be boxed when this function is called, that is, for the following form.
- int n = 10;
- Object.ReferenceEquals n, n );
This is because the data of n is packed twice, and the address after each packing is different, the result of Object. ReferenceEquals n, n is always false.
For the first C # judgment function, there is no good extension, because it has done well.
For the static function of the second Object. Equals, the form is as follows:
- public static bool Equals object left, object right );
According to the analysis in the book, the approximate function code is as follows:
- public static void Equals object left, object right )
- {
- // Check object identity
- if left == right )
- return true;
- // both null references handled above
- if left == null ) || right == null ) )
- return false;
- return left.Equals right );
- }
- C # Implementation of message sending between applications
- Introduction to C # Time
- Analysis on the technical features of C # interfaces and abstract classes
- A c # Time computing instance
- C # detailed inheritance knowledge