Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixing VB.Net and C# Code in an ASP.Net Web Site project?

Tags:

The question quite an older and often asked around, i have similar questions here but my question is a bit more specific.

Q1. Is it legal to mix C# and VB.Net code in ASP.Net Web site? Will it work or not? If it works how it may be done? Any sample will be good.

Q2. If there are any repercussions of mixing C# and VB.Net code then please do share those as well.

I have a web project that is coded in VB.Net. I am working on one module of the project. and i want to code in C#. I cant convert the whole project to C# because i am not the only one working on the project. However, the module i intend to build , i want to have that built in C#.

I have heard that in case of web projects, if we code part in C# and part in VB.net then there are problems compiling the project to a dll. Is that true? if yes then what is the solution.

Also, if i am building a dynamic link library in .Net then can i mix C# and Vb.Net code?

like image 383
Steve Johnson Avatar asked Feb 26 '10 06:02

Steve Johnson


People also ask

Can you mix VB.NET and C#?

Answers. Hi, you cannot use C# and VB in the same project, but you can use C# projects and VB projects in the same solution. I would suggest breaking up the work into seperate projects, but ideally you would both use the same language which would make working on eachothers code a lot easier.

Can you use C# in Visual Basic?

Universal Windows PlatformWindows 10 apps you build with C# and Visual Basic run as fast as C++ with the . NET Native runtime.

Is VB.NET still used 2021?

The language index still believes in Visual Basic. The net will certainly “one way or another enter into decline”, but acknowledges it's preferred for devoted workplace applications in little as well as moderate ventures, and also is most likely still utilized by numerous programmers since it's easy to find out.

Is VB.NET easier than C#?

VB.NET uses implicit casting and makes it easier to code whereas in C# there are lot of casting and conversions needs to be done for the same lines of code. Another aspect to be noted is that the identifiers in VB.NET are not case-sensitive.


1 Answers

From http://msdn.microsoft.com/en-us/library/t990ks23.aspx:

Multiple Programming Languages in the App_Code Folder

Because the source code in the App_Code folder is compiled into a single assembly, all the files in the App_Code folder must be in the same programming language. For example, the App_Code folder cannot include source code in both Visual Basic and C#.

However, you can configure your Web application to treat subfolders of the App_Code folder as separate compilable units. Each folder can then contain source code in a different programming language. The configuration is specified by creating a codeSubDirectories element in the compilation element of the Web.config file and adding a reference to the subfolder. The following example illustrates how you would configure subfolders named VBCode and CSCode to compile into separate assemblies:

<compilation debug="false">     <codeSubDirectories>         <add directoryName="VBCode" />         <add directoryName="CSCode" />     </codeSubDirectories> </compilation> 

The references to the VBCode and CSCode subfolders do not need to include any information about what programming language is contained in the subfolder. As with the App_Code folder itself, ASP.NET infers the compiler to use based on the files in the subfolder.

like image 96
Gabe Avatar answered Sep 24 '22 21:09

Gabe