المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Why Dns.Resolve Method in C# is obsolete ? Workaround?



C# Programming
12-29-2009, 06:21 AM
I am trying to write a small function in C# by passing this DNS name www.google.com
And the function should return the host IP , it is like querying DNS server!
I wrote the following program , but it seems there this Warning

Warning 1 'System.Net.Dns.Resolve(string)' is obsolete: 'Resolve is obsolete for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202' D:\CoDoNS\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 26 20 WindowsFormsApplication1


Using System;
Using Sytem.Net;
namespace BuilderExamples {
class BuilderIPAddress {
static void Main(string[] args) {
try {
IPHostEntry iphe = Dns.Resolve("www.google.com");
foreach (IPAddress addr in iphe.AddressList)
{
Console.WriteLine("AddressFamily: " + addr.AddressFamily.ToString());
Console.WriteLine("Address: " + addr.ToString());
}
}
catch (Exception e) {
Console.WriteLine("Error: " + e.ToString());
}
} } }

Why Dns.Resolve Method in C# is obsolete ?
is the a workaround to get that function done?

Thanks