Reputation: 7907
I wanna use the C# code file in VB.Net project Which is windows based application. But that C# class is not using in VB.NET application. How Can I perform this task.
Thanks
Upvotes: 12
Views: 52411
Reputation: 141
It is very simple to combine your VB.net & C#.net project.
Step1- Add projects which you wanna combine to a single solution.
Step2- Within any one project VB/C# in which you want to call classes from other language project "Goto- Add Reference- Projects" and select the other project which will be automatically displayed.
Step3- After adding the reference just add "Imports (in VB)" or "using (in C#)" statements to your code.
Step4- bingooo!!! now you can use your VB/C# classes in another language.
(tip: You can go only in one direction here i.e. either you can use your C# classes in VB.net or vice versa.)
All the best
Upvotes: 14
Reputation: 18670
It is possible, check this: http://bytes.com/topic/net/answers/49259-mixing-vb-net-c-same-project
However, it is possible to use different languages in a single project. You may need to write command line build file to build the project. In .NET framework SDK, there is one sample on it. You could access it in C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Samples\Technologies\CrossDevLan guage.
This sample demonstrates the use different development languages in a single project. This sample creates two assemblies. The first is a library or DLL assembly that defines a simple base class written in managed extensions for C++. The second assembly is an executable assembly that defines three derived classes written in C#, VB, and IL (Intermediate Language). These types derive from each other and ultimately from the base class written in managed C++. Finally, the executable creates instances of each of the derived types and calls a virtual method for each. The .NET Framework is an environment where various developers can work together seamlessly while developing in their language of choice.
Upvotes: 1
Reputation: 29956
Compile the C# class in it's own C# class library (DLL) and then in your VB project, add a reference to the C# DLL. You can then use the class in your VB project.
If, however, you want to include the source code of the C# class in your VB project then you will have to convert the class from C# to VB. There are various methods of doing this, such as the online tool Convert C# to VB.NET
Upvotes: 13
Reputation: 3428
You can also add the reference for an executable, if it is a .NET assembly. So just compile your C# project and add it as reference into your VB project.
Upvotes: 7