Since IPEndpoint
contains a ToString()
method that outputs:
10.10.10.10:1010
There should also be
If the port number is always provided after a ':'
, the following method may be a more elegant option (in code length instead of efficiency).
public static IPEndpoint ParseIPEndpoint(string ipEndPoint) {
int ipAddressLength = ipEndPoint.LastIndexOf(':');
return new IPEndPoint(
IPAddress.Parse(ipEndPoint.Substring(0, ipAddressLength)),
Convert.ToInt32(ipEndPoint.Substring(ipAddressLength + 1)));
}
It works fine for my simple application without considering complex IP address format.