, :
public static bool NumericalEquals(object x, ulong y)
{
var unsigned = (x as byte?) ?? (x as ushort?) ?? (x as uint?) ?? (x as ulong?);
if (unsigned.HasValue)
{
return (unsigned.Value == y);
}
var signed = (x as sbyte?) ?? (x as short?) ?? (x as int?) ?? (x as long?);
return (signed.HasValue) && (signed.Value >= 0) && ((ulong) signed.Value == y);
}
3 (, object sbyte? long?, ulong), Nullable<T> ab, , , .
[]
, : is . - 1 is 2 cast. , , .
[edit 2]
, :
public static bool NumericalEquals(object x, ulong y)
{
if (x.GetHashCode() != y.GetHashCode()) return false;
...
}