You should probably check to see if obj null. In case of zero return 0 . Honestly, your implementation for long Id is exactly the same as the .NET Framework GetHashCode for long . In other words, you can just call obj.Id.GetHashCode() after checking with non-zeros.
source share