private IPAddress _ipAddr;
private portParam;
// ------
// ------
if (!IPAddress.TryParse(txtIP.Text, out _ipAddr))
{
MessageBox.Show("IP地址不合法!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return false;
}
if (portParam != string.Empty)
{
if (!int.TryParse(portParam, out _port) || _port < 1023 || _port > 65535)//很是精炼的语句
{
_port = 8888;
Console.WriteLine("端口号不合法,默认端口号被接受!");
}
}