Should the hash code of null always be zero, in .NET

前端 未结 9 2283
梦谈多话
梦谈多话 2020-12-13 16:57

Given that collections like System.Collections.Generic.HashSet<> accept null as a set member, one can ask what the hash code of null

9条回答
  •  有刺的猬
    2020-12-13 17:30

    Tuple.Create( (object) null! ).GetHashCode() // 0
    Tuple.Create( 0 ).GetHashCode() // 0
    Tuple.Create( 1 ).GetHashCode() // 1
    Tuple.Create( 2 ).GetHashCode() // 2
    

提交回复
热议问题