事件提供通知,索引子提供陣列式存取,兩者皆為 C# 首創(C/C++ 無對應概念)。
class ResolveDNS {
IPAddress[] IPs;
public void Resolve(string host) {
var entry = Dns.GetHostByName(host);
IPs = entry.AddressList;
}
public IPAddress this[int idx] => IPs[idx];
public int IPLength => IPs.Length;
}
ResolveDNS r = new ResolveDNS();
r.Resolve("www.sohu.com");
for (int i=0;i
csc /r:System.Net.dll /out:resolver.exe resolver.cs