1

My program uses IPHostEntry and DNS, i know i have to add System.Object, System.Net.IPHostEntry, System.Net.DNS to my project reference but i can not find it in the list.

After the System.IO.Log the next to follow is System. Management (no System.Object)

After the System.Net is System.Numerics (no System.Net.IPHostEntry or System.Net.DNS)

I am using .NET 4.0

What do i do to add the following reference and make it work?

i have the following codes

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;
    }
4

1 回答 1

2

类属于程序集并存在于命名空间中。

引用程序集。您可以使用全名(命名空间 + 类名)在代码中指定类,也可以在using指令中添加某些命名空间。

因此,您需要从文档中找到每个类所属的位置,然后确保您引用了这些程序集:

IPHostEntry并且Dns属于System.Net命名空间并且在System程序集中。

Object属于System命名空间并且在mscorlib.

您几乎可以肯定已经引用了这些程序集。但是您可能想using在代码文件的开头添加指令。


添加:

using System.Net;

到你的using指令(你已经有一个using System;参考Object

于 2013-06-24T07:10:06.803 回答