【发布时间】:2022-11-13 07:59:26
【问题描述】:
代码是:
public static bool IsValidIp(string ipAddres)
{
string[] sNumbers = ipAddres.Split('.');
int[] iNumbers = new int[sNumbers.Length];
for(int i = 0; sNumbers.Length > i; i++){
iNumbers[i] = Convert.ToInt32(sNumbers[i]);
}
return 255 >= iNumbers.Max();
}
错误:
System.FormatException : Input string was not in a correct format.
我尝试了几个输入,例如:“0.0.0.0”、“12.255.56.1”、“137.255.156.100”。 它不断返回相同的错误消息。
【问题讨论】:
标签: c# string type-conversion integer