Net-informations.com

# Difference between a.Equals(b) and a == b

a.Equals(b) or a == b ?

In .Net Framework data types can be classified according to whether a variable of a particular type stores its own data or a pointer to the data. If the variable stores its own data, it is a value type and if it holds a pointer to data elsewhere in memory it is a reference type. You can assign either a reference type or a value type to a variable of the Object data type

The Equals() and == operator are used for comparison and both returns the boolean value (true/false).

Value Type

For Value Type == and Equals() works in the same way, both compare two object by value.

a==b and a.Equals(b) returns true , because in this case both compare two object by value.

Reference Type

In case of Reference Type both works in different way.

sb1 == sb2 returns false and sb1.Equals(sb2) returns true.

== operator compares reference returns true when both references point to the same object and Equals() compares object by value and it will return true if the references refers object which are equivalent.

net-informations.com (C) 2023    Founded by raps mk
{"ft_lang_label":"__label__en","ft_lang_prob":0.77847314,"math_prob":0.9890336,"size":1065,"snap":"2022-40-2023-06","text_gpt3_token_len":230,"char_repetition_ratio":0.15834118,"word_repetition_ratio":0.021276595,"special_character_ratio":0.22816901,"punctuation_ratio":0.08056872,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95221996,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-01-29T06:26:01Z\",\"WARC-Record-ID\":\"<urn:uuid:e58bc8b8-d416-497c-871c-68f0ec46db01>\",\"Content-Length\":\"15100\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:48be4444-310d-4fb0-ad5d-4d39a13ad339>\",\"WARC-Concurrent-To\":\"<urn:uuid:8a2c0f17-ee8a-427f-8e33-28946a5ced4c>\",\"WARC-IP-Address\":\"107.180.46.197\",\"WARC-Target-URI\":\"http://net-informations.com/faq/general/equals.htm\",\"WARC-Payload-Digest\":\"sha1:G563U6JKIZODZ3NKRNGQ3OSYF7KKPDEY\",\"WARC-Block-Digest\":\"sha1:M2GKE7I454S3KUR2E4UOQKWFB46CMQPZ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764499700.67_warc_CC-MAIN-20230129044527-20230129074527-00534.warc.gz\"}"}