2010-06-26 126 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()] 

初始化字符串的二維數組,你需要提供兩個整數(行數和列數)。您提供的是兩個字符串:本地端點轉換爲字符串,遠程端點轉換爲字符串