2010-06-26 90 views
1
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无法隐式转换类型“字符串”到“廉政”这个语法有什么问题?

回答

10

看起来你的数组初始化是搞砸了:)

new string[info.LocalEndPoint.Port.ToString(), info.RemoteEndPoint.Port.ToString()], 

也许你的意思

new string[]{info.LocalEndPoint.Port.ToString(), info.RemoteEndPoint.Port.ToString()}, 

0

您在这里创建一个二维数组

new string[info.LocalEndPoint.Port.ToString(), info.RemoteEndPoint.Port.ToString()] 

初始化字符串的二维数组,你需要提供两个整数(行数和列数)。您提供的是两个字符串:本地端点转换为字符串,远程端点转换为字符串