什么是IPHostEntry和DNS正确的命名空间? [英] What is the proper namespace for IPHostEntry and DNS?

查看:1214
本文介绍了什么是IPHostEntry和DNS正确的命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序使用IPHostEntry和DNS,我知道我必须要System.Object的,System.Net.IPHostEntry,System.Net.DNS添加到我的项目的参考,但我找不到它在列表中。

在System.IO.Log后跟随接下来就是系统。管理(无System.Object的)

在该System.Net是System.Numerics(无System.Net.IPHostEntry或System.Net.DNS)

我使用.NET 4.0

我该怎么办,添加以下引用,并使其发挥作用?

我有以下codeS

 使用系统;
System.Collections中使用;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data这;
使用System.Drawing中;
使用System.Globalization;
使用System.Linq的;
使用System.Net.NetworkInformation;
使用的System.Net.Sockets;
使用了System.Runtime.InteropServices;
使用System.Security.Permissions;
使用System.Text;
使用的System.Threading;
使用System.Windows.Forms的;
    公共字符串LocalIPAddress()
    {
        IPHostEntry主机;
        字符串localIP =;
        主机= Dns.GetHostEntry(Dns.GetHostName());
        的foreach(ip地址IP在host.AddressList)
        {
            如果(ip.AddressFamily == AddressFamily.InterNetwork)
            {
                localIP = ip.ToString();
                打破;
            }
        }
        返回localIP;
    }
 

解决方案

类属的组装的和存在的命名空间的。

您的引用的组件。通过使用他们的全名(命名空间+类名)指定的类在code,也可以在的 使用指令的。

所以,你需要找到,从文档,每个类所属然后确保你在引用这些组件:

IPHostEntry DNS 属于 System.Net 的命名空间,并在系统组装。

对象 属于系统命名空间和在的mscorlib

您几乎可以肯定已经有引用这些程序集。但是你可能想在你的code文件的头部添加使用指令。


地址:

 使用System.Net;
 

你的使用指令(你已经有一个使用系统; 为参照对象

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

解决方案

Classes belong to assemblies and exist in namespaces.

You reference assemblies. You specify classes in your code by using their full name (namespace + class name) or you can add certain namespaces in using directives.

So you need to find, from the documentation, where each class belongs and then ensure that you're referencing those assemblies:

IPHostEntry and Dns belong to the System.Net namespace and are in the System assembly.

Object belongs to the System namespace and is in mscorlib.

You almost certainly already have references to these assemblies. But you might want to add using directives at the head of your code file.


Add:

using System.Net;

to your using directives (you already have a using System; for referring to Object)

这篇关于什么是IPHostEntry和DNS正确的命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆