简体   繁体   English

结合C#.NET和VB.NET的缺点

[英]Drawbacks of combining C#.NET and VB.NET

I'm a long time VB.NET developer and has recently switched to C#. 我是VB.NET的开发人员,最近转向C#。 I found out that some of the built-in VB.NET functions (which predates .NET back to 6.0 and BASIC itself) such as the String.Left , or Right , or advanced functions like saving to the registry ( SaveSettings and GetSettings ) are noticeably absent. 我发现一些内置的VB.NET函数(早于.NET回溯到6.0和BASIC本身),如String.LeftRight ,或高级函数,如保存到注册表( SaveSettingsGetSettings ),明显缺席。

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. 我所做的是在VB.NET作为其语言的同一解决方案中创建一个新项目,并基本上重新创建我需要的所有VB.NET中可用的功能。 And then I just call that to the C# code I'm writing. 然后我只是将其称为我正在编写的C#代码。

Since compiling the code in .NET pretty much boils down to the same CIL, it shouldn't matter performance-wise what language I wrote the code in or whether I mix C# with VB. 由于在.NET中编译代码几乎归结为相同的CIL,因此在性能方面我编写代码的语言或者是否将C#与VB混合在一起并不重要。

Am I wrong or right? 我错了还是对的?

Thanks 谢谢

There is a namespace named Microsoft.VisualBasic , you can use it in C# projects also: 有一个名为Microsoft.VisualBasic的命名空间,您也可以在C#项目中使用它:

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

Don't forget to add Microsoft.VisualBasic into References of your project. 不要忘记将Microsoft.VisualBasic添加到项目的引用中。

我建议构建它,然后使用reflector / ilspy / whatever反编译回C#:)

In my experience, it's been almost entirely a matter of preference and experience one has with a language. 根据我的经验,这几乎完全取决于人们对语言的偏好和经验。 You're right to guess that it doesn't matter performance-wise -- both languages are built with the purpose of generating IL and to target the CLR. 你是正确的猜测它在性能方面无关紧要 - 这两种语言都是为了生成IL并以CLR为目标而构建的。

There are other debatable considerations to make when choosing a language as some features that are fully supported in one language are not supported by another. 在选择语言时还有其他值得考虑的因素,因为一种语言完全支持的某些功能不受另一种语言的支持。 Also, some languages are just more expressive for certain purposes such as APL for mathematical calculations. 此外,某些语言对于某些目的而言更具表现力,例如用于数学计算的APL。

While using the Microsoft.VisualBasic namespace is a good solution, VB.NET has the equivalent functionality (although the string functions are zero-based rather than 1-based), eg 虽然使用Microsoft.VisualBasic命名空间是一个很好的解决方案,但VB.NET具有相同的功能(尽管字符串函数是从零开始而不是从1开始),例如

        string str = "abcdefg";

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

BTW, the registry access methods are in the Microsoft.Win32 Namespace: see RegistryKey etc. 顺便说一句,注册表访问方法在Microsoft.Win32命名空间中:请参阅RegistryKey等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM