Using VB.NET From CSharp
Back when I was teaching .NET to other programmers regularly, I would frequently get the following question from a VB6 programmer moving to CSharp.
“Is there any way of using some of the VB functions I’m used to using within CSharp?”
The answer to this question has two parts, which we will explore today.
The first part to this question is, “I can’t remember the last time I NEEDED to do this.” Actually, I’ve never needed to do this. It might have made my life a little easier to replace 3 lines of code with one VB call, but I’m so used to programming in CSharp now that I hardly even notice.
However, the point of this article is not so much that you might need to do this as that you can. In fact, you can use functionality from any .NET language from any other .NET language using a similar approach.
The first thing you’ll want to do is to add a reference to the language library for the language you want to use in your code. In the case of VB.NET, you’ll load the Microsoft.VisualBasic.* assemblies
Next, you’ll want to browse the “Class View” to find out where each of the functions are. By doing this, I can see that the MsgBox function is in the “Interaction” class inside of the Microsoft.VisualBasic namespace located in the Microsoft.VisualBasic assembly
So to use this function, I add a using statement at the top of my code to use the Microsoft.VisualBasic namespace and call the MsgBox function through the Interaction class
using Microsoft.VisualBasic;
Interaction.MsgBox("Message goes here", MsgBoxStyle.OkCancel, "Title goes here");
Other post in Advanced CSharp
- Two Interfaces. Same Method. Two meanings. - September 29th, 2008
- Making values nullable - October 9th, 2008
- CSharp's Property Shortcuts - October 23rd, 2008
- Readonly variables in CSharp? Really?! - October 29th, 2008
- Dispose with Using - November 10th, 2008
- Delegates in .NET - December 4th, 2008
- Using Sealed in CSharp - December 8th, 2008
- CSharp checked and unchecked - December 11th, 2008
- Advanced CSharp - unsafe mode - December 15th, 2008
- Volatile variables and CSharp threads - December 22nd, 2008
- What is the global keyword in CSharp? - December 29th, 2008
- CSharp fixed keyword - January 5th, 2009
- using - There's more there than you are using - February 2nd, 2009
- Stackalloc in CSharp - February 16th, 2009
- Removing Warnings from CSharp Compile Cycle - March 10th, 2009
- && vs & and | vs ||... What's the difference? - March 16th, 2009
- Advanced CSharp - yield - March 25th, 2009
- Just say “No!” to C# Regions? Really?! - April 16th, 2009
- C# “” better than string.Empty? - April 20th, 2009
- .Net String Pool – Not Just For The Compiler - April 22nd, 2009
- CSharp ?? Operator - May 18th, 2009
- Using VB.NET From CSharp - July 1st, 2009
- Dispose, Finalize and SuppressFinalize - July 9th, 2009
- What is .NET’s Object.GetHashCode() Used For? - August 5th, 2009
- ASP.NET Substitution Control - October 22nd, 2009
Other Related Items:
Microsoft Visual Studio Professional 2005 [OLD VERSION]Visual Studio 2005 Professional Edition offers developers exactly what they need: A high productivity professional development environment for working... Read More >










This is awesome information, with this things to do will be much be easier, I will explore Csharp more …thanks.. looking for more bright ideas from you…