开发者

Possible to combine C#.net, VB.net and ASP.net?

开发者 https://www.devze.com 2023-02-21 13:16 出处:网络
I want to build a website in ASP.net, and to integrate a module which i开发者_运维问答s written in C#(too complicated to rewrite in VB or ASP).

I want to build a website in ASP.net, and to integrate a module which i开发者_运维问答s written in C#(too complicated to rewrite in VB or ASP).

Now I just want to know whether it is possible to have a website that integrates all three?

Thank you.


Yes. You can have a WebSite integrating all three.

Just make your complicated C# a .NET library and include it in your VB.NET/ASP.NET project.


I think you only have to reference the dll's from your modules which are written in c# or VB to call your public functions. I've done this in a windows form application and it worked fine.


You may also want to consider simply learning C#. Most of what you know from VB.NET is directly usable in C#, since most work involves using framework classes and the languages share most features.

It is mostly a matter of syntactic preference, and while a new syntax may sting your eyes for a bit the learning curve will be steep and soon you will have left your old preferences behind.


You have a couple of options when integrating languages in ASP.NET. If you're creating a "web site" (as opposed to a "web application" which can use only one language) then each page can use a specified language, because essentially each page is compiled separately. Some can use VB, some can use C#. No problem.

However, what you describe sounds even simpler. You claim that there is an existing C# module which you want to use in your VB website. Is this module compiled into its own assembly? If that's the case then the language that was used to create the assembly is immaterial. Once it's compiled, it's a .NET assembly and can be referenced by any .NET language. It's no longer a matter of VB vs. C# (or any other language) once it's compiled.

If it's not a compiled assembly, but rather a bunch of class files, can it be compiled as its own assembly? That's generally good for keeping things modular. Within a single .NET solution you can have each project use different languages without problem. This module can be a library project written in C# and your site can be a web site (or web application) project written in VB, which references the library project.


Since all these assemblies ultimatly use the same CLR (hence the name Common Language Runtime), they can be used together with no problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消