Why casting to object when comparing to null?

后端 未结 5 1849
故里飘歌
故里飘歌 2021-01-07 21:04

While browsing the MSDN documentations on Equals overrides, one point grabbed my attention.

On the examples of this specific page, some null checks are made, and the

5条回答
  •  情深已故
    2021-01-07 21:50

    As others said, the type might override the == operator. Therefore, casting to Objectis equivalent to if (Object.ReferenceEquals(p, null)) { ... }.

提交回复
热议问题