Equals(item, null) or item == null

后端 未结 6 1281
深忆病人
深忆病人 2020-12-07 23:14

Is code that uses the static Object.Equals to check for null more robust than code that uses the == operator or regular Object.Equals? Aren\'t the latter two vulnerable to b

6条回答
  •  感动是毒
    2020-12-07 23:31

    In reference to "...writing code that will handle objects outside the author's control...", I would point out that both static Object.Equals and the == operator are static methods and therefore cannot be virtual/overridden. Which implementation gets called is determined at compile time based on the static type(s). In other words, there is no way for an external library to provide a different version of the routine to your compiled code.

提交回复
热议问题