예제 #1
0
        /// <summary>Determines whether a string is a valid IP address.</summary>
        /// <returns>true if <paramref name="ipString" /> is a valid IP address; otherwise, false.</returns>
        /// <param name="ipString">The string to validate.</param>
        /// <param name="address">The <see cref="T:System.Net.IPAddress" /> version of the string.</param>
        public static bool TryParse(string ipString, out IPAddress address)
        {
            if (ipString == null)
            {
                throw new ArgumentNullException("ipString");
            }
            IPAddress ipaddress;

            address = (ipaddress = IPAddress.ParseIPV4(ipString));
            if (ipaddress == null)
            {
                address = (ipaddress = IPAddress.ParseIPV6(ipString));
                if (ipaddress == null)
                {
                    return(false);
                }
            }
            return(true);
        }