public static void PullData(Hashtable source)
{
IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
//IPEndPoint[] endPoints = ipProperties.GetActiveTcpListeners();
TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections();
foreach (TcpConnectionInformation info in tcpConnections)
{
if (!(info.RemoteEndPoint.Address.ToString() == "192" || info.RemoteEndPoint.Address.ToString() == "127"))
{
source.Add(info.RemoteEndPoint.Address.ToString(), new IPInstance(
new string[info.LocalEndPoint.Port.ToString(), info.RemoteEndPoint.Port.ToString()],
info.RemoteEndPoint.Address.ToString(),
Dns.GetHostEntry(info.RemoteEndPoint.Address.ToString())
));
}
}
}
我一直收到错误1无法将类型'string'隐式转换为'int'
答案 0 :(得分:10)
看起来您的阵列初始化程序搞砸了:)
new string[info.LocalEndPoint.Port.ToString(), info.RemoteEndPoint.Port.ToString()],
也许你的意思是
new string[]{info.LocalEndPoint.Port.ToString(), info.RemoteEndPoint.Port.ToString()},
答案 1 :(得分:0)
你在这里创建一个二维数组
new string[info.LocalEndPoint.Port.ToString(), info.RemoteEndPoint.Port.ToString()]
要初始化二维数组的字符串,您需要提供两个整数(行数和列数)。你提供的是两个字符串:本地端点转换为字符串,远程端点也转换为字符串