Hi Lloyd,
Thanks for posting to the newsgroup.
You could potentially run this through a regular expression to see if it's
in the right format for either a machine name or an IP address and then use
the appropriate method -- Parse() or GetHostByName(). I'd still use the try
/ catch block in case there are any problems you miss.
Hope this helps,
bliz
--
Jim Blizzard, MCSD .NET
Community Developer Evangelist |
http://www.microsoft.com/communities
Microsoft
Your Potential. Our Passion.
This posting is provided as is, without warranty, and confers no rights.
"Lloyd Dupont" <net.galador@ld> wrote in message
news:OP**************@TK2MSFTNGP11.phx.gbl...
In my App the user could manually enter some host computer location
for this he has the choice to enter either the IP or host name.
I get the IP address internally with the following code sample:
IPAddress ia;
try
{
ia = IPAddress.Parse(host);
}
catch(FormatException)
{
IPHostEntry he = Dns.GetHostByName( host );
ia = he.AddressList[0];
}
I wonder if there is another way to do that which would avoid the try
catch, any tips ?