IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("192.168.1.1"), 80); string endPointString = endPoint.ToString(); Console.WriteLine(endPointString); // Output: "192.168.1.1:80"
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 0); socket.Bind(endPoint); string endPointString = socket.LocalEndPoint.ToString(); Console.WriteLine(endPointString); // Output: "0.0.0.0:0"In this example, we create a Socket instance and bind to an IPEndPoint with the IP address "any" and port number 0. We then call the ToString method on the LocalEndPoint property of the socket, which returns the string "0.0.0.0:0". The EndPoint class is part of the System.Net namespace in the .NET framework.