Most developers tend to think in the context of the language they are currently writing.  If you’re writing C#, you are accustomed to having the core .NET Framework class library at your disposal.  If you’re writing VB.NET, you’re used to having many more classes above and beyond the core class library, and in J# (assuming anyone actually uses J#) you have yet another pool of classes to choose from.  This language-specific focus can lead to an unfortunate bit of tunnel vision.

To make a stunningly obvious point (once you think about it for a minute): your C# application is free to use any class available in the VB.NET or J# class libraries (or any others).  Your VB.NET application is free to use any class available in the J# class library, and so on.  Whatever language you are using, you can, and should, take advantage of all of the class libraries available to you!  Less work and less custom coding is always a great thing.

In the context of a C# application, this means adding a reference to Microsoft.VisualBasic.dll.  (What? Is he nuts?!?)  Sure, it might seem odd at first, but all high-level language code for .NET is reduced to one intermediate language in a managed code assembly — IL.  It makes no difference if it originated in COBOL.NET, C#, VB.NET, J#, etc., and there is absolutely nothing wrong with having “using Microsoft.VisualBasic” in your C# code.  The core .NET Framework already includes the extra VB class libraries, but to get the J# class libraries you need to have the J# Runtime installed.

There is a lot of great code just waiting to be used.  For example: need to work with ZIP files (unlike System.Compression)?  Check out the java.util.zip namespace in the J# runtime.  Yeah, that’s .NET managed code, despite the “java” in the namespace.  Remember that the J# runtime and J# itself was designed to be compatible with Java, so the runtime attempts to recreate as much of the (older) Java class libraries as possible.  Another example: the Microsoft.VisualBasic.Financial class.  How cool is this?  Asset depreciation calculation, present value of an annuity and more.  If you’re coding in C#, you may well have gone off and coded all of this yourself, or looked to open source for a solution — all while it was right under your nose.

I found an old article from MSDN magazine that demonstrates writing a ZIP utility in C# using the J# runtime, which is a great example for this topic.

Some of you will be saying “Duh!” by this time, but the reactions from years of saying this to developers has told me that it is not immediately obvious to everyone.  Hopefully this will save you some time!

%d bloggers like this: