How to make a DLL file and use it in C#

I am assuming that you know about dll files.So i am going to show you a simple way by which you can make a dll file and can use it.There are many other ways also but this is the simplest.

1.Open new project and select "class library", and choose location where you want to save it.
2.Now create a simple function in class1 as shown below.You can add classes and functions as much as you need but for simplicity i am just writing 1 function "add" which add two numbers and returns the result.
3.Now Build Solution from menu bar
4.Your DLL file is ready and it will be in the debug folder of the project as shown below
the dll file that you have just created can be copied and pasted anywhere and can be used by number of programs.
5.Now create new windows application in C#
6.Build the windows form according to your need, i am just adding a button to the form
7.Now add reference off the DLL file that you have created.
8.We will use class and namespace of the dll file we had created
9.Double click on the button to create event handler and write the code as shown in templates below.
10.Now run the program and output will be according to the parameters that yiu passed to add function in your dll file.i passed 1 & 2 so output should be 3 :P
I hope this will help you :P

0 comments:

Post a Comment