Câu hỏi phỏng vấn C#
Câu hỏi

What is the difference between Equality Operator ( == ) and Equals() Method in C#?

Câu trả lời

Here is the difference between the equality operator (==) and the Equals() method in C#:

Equality Operator (==)

  • The equality operator (==) compares the values of two operands.
  • For value types (e.g., int, double, char), it compares the actual values stored in the variables.
  • For reference types (e.g., string, arrays, classes), it compares the references (memory addresses) of the objects, not their contents.
  • If the operands are of different types, the == operator returns false.

Equals() Method

  • The Equals() method is a virtual method inherited from the Object class.
  • It can be overridden in derived classes to provide custom comparison logic.
  • For value types, the default implementation of Equals() uses the == operator for comparison.
  • For reference ty...
middle

middle

Gợi ý câu hỏi phỏng vấn

expert

What is the use of static constructors?

senior

What is difference between late binding and early binding in C#?

middle

Explain the difference between Task and Thread in .NET

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào