Tuesday, January 2, 2018

C# difference between == and Equals()


== Operator

1. If operands are Value Types and their values are equal, it returns true else false.
2. If operands are Reference Types with exception of string and both refer to same object, it returns true else false.
3. If operands are string type and their values are equal, it returns true else false.

.Equals

1. If operands are Reference Types, it performs Reference Equality that is if both refer to same object, it returns true else false.
2. If Operands are Value Types then unlike == operator it checks for their type first and If their types are same it performs == operator else it returns false.

No comments: