2013-06-24 22 views
1

我的程序使用IPHostEntry和DNS,我知道我必須添加System.Object,System.Net.IPHostEntry,System.Net.DNS到我的項目引用,但我無法在列表中找到它。什麼是IPHostEntry和DNS的正確命名空間?

在System.IO.Log之後,接下來是System。管理(無System.Object的)

的System.Net後System.Numerics(無System.Net.IPHostEntry或System.Net.DNS)

我使用.NET 4.0

做什麼我確實要添加以下參考並使其工作?

我有以下代碼

using System; 
using System.Collections; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Globalization; 
using System.Linq; 
using System.Net.NetworkInformation; 
using System.Net.Sockets; 
using System.Runtime.InteropServices; 
using System.Security.Permissions; 
using System.Text; 
using System.Threading; 
using System.Windows.Forms; 
    public string LocalIPAddress() 
    { 
     IPHostEntry host; 
     string localIP = ""; 
     host = Dns.GetHostEntry(Dns.GetHostName()); 
     foreach (IPAddress ip in host.AddressList) 
     { 
      if (ip.AddressFamily == AddressFamily.InterNetwork) 
      { 
       localIP = ip.ToString(); 
       break; 
      } 
     } 
     return localIP; 
    } 
+0

'System.Object'不是一個命名空間。這是一堂課。誰讓你添加這樣的參考?現在有什麼問題?你的代碼是不是編譯? – horgh

+0

我不能添加system.object當我添加它的對象變成藍色與紅色的波浪線 –

+0

好吧,我認爲我得到它對象上的帽「O」是問題...對於麻煩先生抱歉。 –

回答

2

類屬於組件命名空間存在。

參考組件。您可以使用全名(名稱空間+類名)在代碼中指定類,也可以在using directives中添加某些名稱空間。

所以,你需要找到,從文檔,其中每一類屬,然後確保你引用這些組件:

IPHostEntryDns屬於System.Net命名空間,並在System組裝。

Object屬於System命名空間,並且在mscorlib中。

你幾乎可以肯定已經引用了這些程序集。但是您可能需要在代碼文件的頭部添加using指令。


地址:

using System.Net; 

using指令(你已經有一個using System;用於參考Object

+0

這些是使用i但仍然無法使用這些方法.... –

+0

在註釋中發佈代碼不會很好,因爲它沒有格式化。這會更好地編輯回你的問題。但從外觀上來看,儘管在System.Net中有兩個名稱空間的''using'',你沒有一個只用於'System.Net'。 –