Disadvantages of combining C # .NET and VB.NET

I have been a VB.NET developer for a long time and recently switched to C #. I learned that some of the built-in functions VB.NET (which precede the .NET back to 6.0 and the BASIC itself), such as String.Leftand Right, or advanced features, such as saving the registry ( SaveSettingsand GetSettings) noticeably absent.

What I did was create a new project in the same solution with VB.NET as its language and recreate basically all the functions I need that are available in VB.NET. And then I just call it the C # code I'm writing.

Since compiling code in .NET pretty much boils down to the same CIL, it doesn't matter how important which language I wrote in the code, or if I mix C # with VB.

Am I wrong or right?

thank

+3
source share
4 answers

There is a namespace with a name Microsoft.VisualBasic, you can also use it in C # projects:

string test = Microsoft.VisualBasic.Strings.Left("abc", 2);

Do not forget to add Microsoft.VisualBasica link to your project.

+12
source

I would recommend building it and then using the / ilspy / reflector to decompile it back to C # :)

+1
source

, , . , , - IL CLR.

There are other controversial considerations when choosing a language, as some features that are fully supported in one language are not supported by another. In addition, some languages ​​are more expressive for specific purposes, such as APL for mathematical calculations.

0
source

Using a namespace Microsoft.VisualBasicis a good solution, VB.NET has equivalent functionality (although the string functions are based on zero, not 1), for example

        string str = "abcdefg";

        string left  = str.Substring(0, 2);                // Left(str, 2)
        string right = str.Substring(str.Length - 2, 2);   // Right(str, 2)

BTW, registry access methods are in the namespace Microsoft.Win32: see RegistryKey, etc.

0
source

All Articles