---
title: "Creating and Using Dll (Dynamic Link Library) in C#"  
description: "In this article I’m explaining how to create and use dl in C#."  
author: "Anonymous User"  
published: 2014-08-26  
updated: 2020-07-11  
canonical: https://www.mindstick.com/articles/1486/creating-and-using-dll-dynamic-link-library-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Creating and Using Dll (Dynamic Link Library) in C#

Previously, we learn about CSS in *CSS-3 And CSS-4.* now we see how to create DLL's in C#

In this article, I’m explaining how to create and use dl in C#.

### 1. Create DLL:

**Open [visual studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) >> Select File >> New >> Project >> Windows >> [Class Library](https://www.mindstick.com/forum/158577/what-is-the-significance-of-the-base-class-library-bcl-in-the-dot-net-framework)**.

Select [your project](https://www.mindstick.com/forum/156583/best-way-to-link-bootstrap-file-in-your-project) name and appropriate directory using the browse button and click

OK.

![Creating and Using Dll (Dynamic Link Library) in C#](http://www.mindstick.com/MindStickArticle/71119fac-933b-4a80-9de7-531bae95dd26/Images/image001.png)

### Project and its file:

In this project [add two](https://www.mindstick.com/forum/480/add-two-number) classes by default Class1.cs and AssemblyInfo.cs inside [properties](https://yourviews.mindstick.com/view/81845/now-it-s-possible-to-predict-properties-of-any-molecule) folder. We will be concentrating only Class1.cs

![Creating and Using Dll (Dynamic Link Library) in C#](http://www.mindstick.com/MindStickArticle/71119fac-933b-4a80-9de7-531bae95dd26/Images/image002.png)

### Calculator Namespace:

When you open Class1.cs then you see [Calculator](https://www.mindstick.com/articles/38/calculator-in-asp-dot-net-using-javascript) [Namespace](https://www.mindstick.com/articles/28/namespace-in-dot-net). We will be

referencing this Namespace in our clients to use this [class method](https://www.mindstick.com/interview/22908/what-are-java-string-class-method).

```
using System; namespace Calculator{    public class Class1    {    }}
```

Now add some calculator method in your project.

```
using System; namespace Calculator{    public class Class1    {        public static int Add(int num1,int num2)        {            return num1 + num2;        }        public static int Sub(int num1, int num2)        {            return num1 - num2;        }        public static int Mul(int num1, int num2)        {            return num1 * num2;        }        public static int Division(int num1, int num2)        {            return num1 / num2;        }    }}
```

Now Build your project after build succeeded generate Calculator.dll file inside bin >> Debug folder.

![Creating and Using Dll (Dynamic Link Library) in C#](http://www.mindstick.com/MindStickArticle/71119fac-933b-4a80-9de7-531bae95dd26/Images/image003.png)

### Use DLL:

Make a client [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) for using the DLL file.

#### Create a console application:

**Open visual studio >> Select File >> New >> Project >> Windows >> Console Application**.

Select your project name and appropriate directory using the browse button and click OK.

![Creating and Using Dll (Dynamic Link Library) in C#](http://www.mindstick.com/MindStickArticle/71119fac-933b-4a80-9de7-531bae95dd26/Images/image004.png)

### Add reference of the Namespace:

Now add a reference to the library. Project >> [Add reference](https://www.mindstick.com/forum/548/how-to-add-reference-to-system-web-optimization)

![Creating and Using Dll (Dynamic Link Library) in C#](http://www.mindstick.com/MindStickArticle/71119fac-933b-4a80-9de7-531bae95dd26/Images/image005.png)\
Now on this page click browse button to browse your library.

![Creating and Using Dll (Dynamic Link Library) in C#](http://www.mindstick.com/MindStickArticle/71119fac-933b-4a80-9de7-531bae95dd26/Images/image006.png)

Use Calculator Namespace and call method.

```
using Calculator; namespace UseDll{    class Program    {        static void Main(string[] args)        {            Console.Write("Enter Your Operator Choice  Add + Sub - Mul * Division /");            char choice = Convert.ToChar(Console.Read());            switch (choice)            {                case '+':                    {                        int add = Class1.Add(10, 20);                        Console.WriteLine("Sum of the two number " + add);                        break;                    }                case '-':                    {                        int sub = Class1.Sub(50, 20);                        Console.WriteLine("Substrack of two integer number " + sub);                        break;                    }                case '*':                    {                        int mul = Class1.Mul(2, 4);                        Console.WriteLine(mul);                        break;                    }                case '/':                    {                        int div = Class1.Division(10, 2);                        Console.WriteLine(div);                        break;                    }                default:                    {                        Console.WriteLine("Wrong input!!");                        break;                    }            }        }    }}
```

Output

![Creating and Using Dll (Dynamic Link Library) in C#](http://www.mindstick.com/MindStickArticle/71119fac-933b-4a80-9de7-531bae95dd26/Images/image007.png)

You may also want to read: Creating C# Class Library (DLL) Using Visual Studio .NET

In my next post, we are going to learn about : Join, Sleep and Interrupt methods in C# Threading

---

Original Source: https://www.mindstick.com/articles/1486/creating-and-using-dll-dynamic-link-library-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
