Back to Browse

Difference between == VS .Equals() | Difference between == operator & .equals () method

1.0K views
May 19, 2021
5:29

In this video, we look at the differences between the equals operator and the equals method | Difference Between Equality Operator ( ==) and Equals() Method in C# |Difference between == and .equals () of an object |Difference between == operator & .equals() method Both the == Operator and the Equals() method are used to compare two value type data items or reference type data items. This article explains the basic difference between these two. The Equality Operator ( ==) is the comparison operator and the Equals() method compares the contents of a string. The == Operator compares the reference identity while the Equals() method compares only contents == Operator If operands are Value Types and their values are equal, it returns true else false. If operands are Reference Types with exception of string and both refer to the same instance (same object), it returns true else false. If operands are string type and their values are equal, it returns true else false. .Equals If operands are Reference Types, it performs Reference Equality that is if both refer to the same instance (same object), it returns true else false. 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. #Interviewquestion #cshart

Download

0 formats

No download links available.

Difference between == VS .Equals() | Difference between == operator & .equals () method | NatokHD