简体   繁体   English

结合C#类和vb.net类

[英]combine c# class and vb.net classes

I am using asp.net 2012 and have c# class project where I would like to include some existing vb.net classes. 我正在使用asp.net 2012并拥有c#类项目,我想在其中包含一些现有的vb.net类。

What would be the best way to be able to use both c# and vb.net classes? 能够同时使用c#和vb.net类的最佳方法是什么?

可以将vb.net类转换为C#,也可以将vb.net类放入其自己的程序集中并添加对该程序集的引用。

将VB.NET类放在自己的项目中,然后像引用任何第三方控件一样引用该项目。

As already mentioned, one of the alternatives is to convert c# to vb.net or vice-versa. 如前所述,替代方法之一是将c#转换为vb.net,反之亦然。 You can find many pages in the internet to do that, like these ones: 您可以在互联网上找到许多页面来执行此操作,例如:

http://www.developerfusion.com/tools/convert/vb-to-csharp/ http://www.developerfusion.com/tools/convert/vb-to-csharp/

http://www.developerfusion.com/tools/convert/csharp-to-vb/ http://www.developerfusion.com/tools/convert/csharp-to-vb/

If you convert the code from one language to the other make sure you test the changes properly. 如果您将代码从一种语言转换为另一种语言,请确保您正确测试了更改。

If you decide to keep VB.NET code in a separate Visual Studio project and reference it in the C# code you need to ensure that the VB.NET code is CLS compliant. 如果决定将VB.NET代码保留在单独的Visual Studio项目中,并在C#代码中引用它,则需要确保VB.NET代码符合CLS。 This is a good starting point: 这是一个很好的起点:

Writing CLS-Compliant Code 编写符合CLS的代码

See also: 也可以看看:

Cross-Language Interoperability 跨语言互操作性

Make C# a .NET library and include it in your VB.NET/ASP.NET project. 使C#成为.NET库,并将其包含在您的VB.NET/ASP.NET项目中。

Follow this http://msdn.microsoft.com/en-us/library/t990ks23.aspx for more info... 请关注此http://msdn.microsoft.com/en-us/library/t990ks23.aspx了解更多信息...

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

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