Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vb.net

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

like image 690
Deepak Avatar asked Feb 08 '10 09:02

Deepak


People also ask

How is C used?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

How do I start C programming?

To start using C, you need two things: A text editor, like Notepad, to write C code. A compiler, like GCC, to translate the C code into a language that the computer will understand.

Is C easy for beginners?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

What is -= in C?

-= Subtract AND assignment operator. It subtracts the right operand from the left operand and assigns the result to the left operand. C -= A is equivalent to C = C - A.


3 Answers

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

like image 152
Adam Ralph Avatar answered Nov 07 '22 18:11

Adam Ralph


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

like image 20
swaps Avatar answered Nov 07 '22 18:11

swaps


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.

like image 44
Simon Linder Avatar answered Nov 07 '22 18:11

Simon Linder