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).
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.
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.
- Difference between a Value Type and a Reference Type
- System level Exceptions Vs Application level Exceptions
- Difference between sub-procedure and function
- What does the term immutable mean
- What does the keyword static mean
- this.close() Vs Application.Exit()
- Difference between Hashtable and Dictionary
- Difference between Exception and Error
- C# Dictionary Versus List Lookup Time
- Difference between the Class and Interface in C#
- Why does C# doesn't support Multiple inheritance