Geeks With Blogs

News



Add to Google

Tim Hibbard CEO for EnGraph software

I decided at HDC 2006 that it was time to make the switch from VB.net to C#.  Not because it is better, but because all the presentations I go to are in C#.  I hate having to convert languages in my head and since I give presentations every now and then, it's not fair to my audience to make them convert in their head.

I've come to my first road block in migrating to C#.  I really like the My. namespace that VB provides and C# doesn't have anything like it.  I need to access the My.Computer.Network.IsAvailable and .Ping functions in my current project.

I know that I can add a reference to Microsoft.VisualBasic and access the Devices.Network namespace, but for some reason that makes me feel dirty. 

So the question I pose to you C# purists, is there a comparable C# function that will provide network status and ping functionality?  If not, should I reference the Microsoft.VisualBasic.dll?  If not, do I create a separate VB assembly that exposes the functionality that I need?

 

Technorati tags: , , ,
Posted on Monday, November 27, 2006 4:26 PM .NET | Back to top


Comments on this post: C# Conversion Conundrum

# re: C# Conversion Conundrum
Requesting Gravatar...
A quick check with Reflector reveils that My.Computer.Network.IsAvailable is simply a syntactic sugar for NetworkInterface.GetIsNetworkAvailable() found in the System.Net.NetworkInformation namespace.

Ping has a little more to it, but not much. It uses the Ping class, also found in the System.Net.NetworkInformation namespace...

PingReply reply1 = new Ping().Send(hostNameOrAddress, timeout, this.PingBuffer);
if (reply1.Status == IPStatus.Success)
{
return true;
}


I too made the switch to C# from VB.NET, and I must say that language wars aside, it's quite nice to use the language that *most* of the .NET developer community uses. I always got tired of having to "translate" C# samples into vb.net in order to use them.
Left by Dusty on Nov 27, 2006 6:44 PM

# re: C# Conversion Conundrum
Requesting Gravatar...
Fantastic. Thanks Dusty!
Left by Tim Hibbard on Nov 27, 2006 6:48 PM

# re: C# Conversion Conundrum
Requesting Gravatar...
I implemented your suggestion this morning and it worked like a champ. Thanks again.

I love the phrase "syntactic sugar" by the way!
Left by Tim Hibbard on Nov 28, 2006 8:35 AM

Your comment:
 (will show your gravatar)


Copyright © Tim Hibbard | Powered by: GeeksWithBlogs.net