System.Net.IPAddress.GetHashCode C# (CSharp) Method

GetHashCode() public method

public GetHashCode ( ) : int
return int
        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);
            }
        }

Usage Example

Esempio n. 1
0
 public bool addIPAddress( IPAddress ip )
 {
     int new_hash = ip.GetHashCode();
     if (ip_hashes.Contains(new_hash))
         return false;
     ip_addresses.Add(ip);
     ip_hashes.Add(new_hash);
     return true;
 }
All Usage Examples Of System.Net.IPAddress::GetHashCode