Wednesday, November 14, 2018

Creating DLL and consuming it using C#


Description
DLL  Stand for  (Dynamic Link Library).
How to create a DLL and consuming it  because most of the reusable components are written in the form of a DLL.


Create DLL.

Step 1
First, create a project of type “Class Library” as shown here.


Then we are implementing a Fullname class library that is responsible for show fullname of user.


Step 3
Build this code and you will see that a DLL file has been created rather than an exe in the root directory of the application (path = C:\Users\Admin\Documents\visual studio 2017\Projects\LibraryForDLL\LibraryForTest\bin\Debug\netstandard1.4\ LibraryForTest.dll).

Consume the DLL
Step 1
 
Now create another console based application(Any project) where we will utilize the class library functionality.In my case i am created new project in same Solution Explorer.

 


Step 2
 
Then you need to add the reference of the Fullname Class Library DLL file reference to access the declared class in the library DLL. (Right-click on the Reference then select Add reference then select the path of the DLL file.)

Step 3
 
When you add the class library reference then you will see in the Solution Explorer that a new LibraryForTest is added as in the following,


Step 4
 
Now add the namespace of the class library file in the console application and create the instance of the class declared in the library as follows,


Step 5
Finally, run the application and you must see the result as shown in the image below.


;;;;;;;;;;;;;;;;;;;;;;;;;Thank you ;;;;;;;;;;;;;;;;;

No comments:

Post a Comment