草庐IT

c# - 为什么 ((object)(int)1).Equals(((object)(ushort)1)) 产生错误?

我的情况是我有一个object,我想检查它与另一个object是否相等。publicstaticboolEquals(objecta,objectb){returna.Equals(b);}当a=1(整数)和b=1(ushort(或基本上不是整数))时会出现问题。我想知道这是否不应该产生true,但它确实返回false...编辑更糟糕的是:Hashtableht=newHashtable();ht.Add((int)1,"SOMESTRING");ht.Add((short)1,"SOMESTRING");ht.Add((long)1,"SOMESTRING");我认为值“1”应该只允