public override int GetHashCode()
{
// For IPv6 addresses, we cannot simply return the integer
// representation as the hashcode. Instead, we calculate
// the hashcode from the string representation of the address.
if (IsIPv6)
{
if (_hashCode == 0)
{
_hashCode = StringComparer.OrdinalIgnoreCase.GetHashCode(ToString());
}
return _hashCode;
}
else
{
// For IPv4 addresses, we can simply use the integer representation.
return unchecked((int)PrivateAddress);
}
}