Lambda Expression: == vs. .Equals()

前端 未结 6 825
名媛妹妹
名媛妹妹 2021-01-07 23:09

This is a purely academic question, but what\'s the difference between using == and .Equals within a lambda expression and which one is preferred?

Code exam

6条回答
  •  清歌不尽
    2021-01-07 23:27

    The Lambda is irrelevant here...

    For value objects == and equals are the same For reference object == will be true if the objects are the same object (points to the same instance) while it is expected that equals compare the contents of the objects. This link explains it in another way.

提交回复
热议问题