展現C# 清單5.10 產生exe檔案執行的問題

來源:互聯網
上載者:User
問題|執行
清單  5.10  通過一個索引擷取一個IP地址

1: using System;
2: using System.Net;
3:
4: class ResolveDNS
5: {
6:  IPAddress[] m_arrIPs;
7:
8:  public void Resolve(string strHost)
9:  {
10:  IPHostEntry iphe = Dns.GetHostByName(strHost);
11:  m_arrIPs = iphe.AddressList;
12:  }
13:
14:  public IPAddress this[int nIndex]
15:  {
16:  get
17:  {
18:    return m_arrIPs[nIndex];
19:  }
20:  }
21:
22:  public int Count
23:  {
24:  get { return m_arrIPs.Length; }
25:  }
26: }
27:
28: class DNSResolverApp
29: {
30:  public static void Main()
31:  {
32:  ResolveDNS myDNSResolver = new ResolveDNS();
33:  myDNSResolver.Resolve("http://www.microsoft.com");
34:
35:  int nCount = myDNSResolver.Count;
36:  Console.WriteLine("Found {0} IP's for hostname", nCount);
37:  for (int i=0; i < nCount; i++)
38:    Console.WriteLine(myDNSResolver[i]);
39:  } 
40: }

編譯環境:

 Visual Studio .NET2003 version 7.1.3091  Microsoft Visual C# .NET  

 Microsoft .NET Framework version 1.1.4322 sp1

產生的exe檔案,執行後報錯:

未處理的“System.Net.Sockets.SocketException”類型的異常出現在 system.dll 中。

其他資訊: The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for

這是為什麼呢?……


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.