gpt4 book ai didi

linux - Dns 不包含 `GetHostEntry' 的定义

转载 作者:太空宇宙 更新时间:2023-11-04 10:11:27 24 4
gpt4 key购买 nike

我来了from powershellMono:

thufir@dur:~/mono$ 
thufir@dur:~/mono$ ls
hello.cs
thufir@dur:~/mono$
thufir@dur:~/mono$ cat hello.cs
using System;

public class HelloWorld
{
static public void Main ()
{
Console.WriteLine ("Hello Mono World");
}
}

thufir@dur:~/mono$
thufir@dur:~/mono$ mcs hello.cs
thufir@dur:~/mono$
thufir@dur:~/mono$ mono hello.exe
Hello Mono World
thufir@dur:~/mono$
thufir@dur:~/mono$ dotnet --version
2.1.4
thufir@dur:~/mono$
thufir@dur:~/mono$ lsb_release --all
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 17.10
Release: 17.10
Codename: artful
thufir@dur:~/mono$

我正在寻找类似这样的powershell one-liner:

Resolve-DnsName -Name localhost -Type ANY | Format-Table -AutoSize

但是来自 Mono。这是 what I have到目前为止:

thufir@dur:~/mono$ 
thufir@dur:~/mono$ ls
dns.cs hello.cs
thufir@dur:~/mono$
thufir@dur:~/mono$ mcs dns.cs
dns.cs(10,35): error CS0117: `Dns' does not contain a definition for `GetHostEntry'
dns.cs(5,14): (Location of the symbol related to previous error)
dns.cs(11,28): error CS0118: `System.Net.IPAddress' is a `type' but a `variable' was expected
dns.cs(11,28): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected
Compilation failed: 3 error(s), 0 warnings
thufir@dur:~/mono$
thufir@dur:~/mono$ cat dns.cs
using System.Net.Sockets;
using System.Net;
using System;

public class Dns
{
static public void Main ()
{
Console.WriteLine ("Hello Mono World");
IPAddress ipAddress = Dns.GetHostEntry("localhost").AddressList[0];
Console.WriteLine (IPAddress);
}
}

thufir@dur:~/mono$

dotnet 的版本是否正确?导入是否正确?

我是否没有使用正确的类型正确声明和实例化 ipaddress 变量?

最佳答案

您自己的类名 Dns 正在覆盖 System.Net 命名空间。试试这个:

using System.Net.Sockets;
using System.Net;
using System;

public class MyDns
{
static public void Main()
{
Console.WriteLine("Localhost: ");
IPAddress ip = Dns.GetHostEntry("localhost").AddressList[0];
Console.WriteLine(ip);
}
}

关于linux - Dns 不包含 `GetHostEntry' 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48841829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com