How to use C# class in VB.NET project in windows application?

后端 未结 4 1016
逝去的感伤
逝去的感伤 2020-12-20 15:18

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.

相关标签:
4条回答
  • 2020-12-20 15:23

    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.

    0 讨论(0)
  • 2020-12-20 15:24

    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

    0 讨论(0)
  • 2020-12-20 15:28

    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

    0 讨论(0)
  • 2020-12-20 15:36

    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.

    0 讨论(0)
提交回复
热议问题