---
title: "DLL in C#"  
description: "A dynamic-link library (DLL) is a module that contains functions and data that can be used by another module (application or DLL)."  
author: "Anonymous User"  
published: 2016-05-05  
updated: 2018-03-27  
canonical: https://www.mindstick.com/articles/12038/dll-in-c-sharp  
category: "c#"  
tags: ["c#", "dll"]  
reading_time: 3 minutes  

---

# DLL in C#

A **dynamic-link library (DLL)** is a module that contains functions and data that can be used by another module (application or DLL). A DLL is a library that contains code and data that can be used by more than one program at the same time\

A DLL can define two kinds of functions: exported and internal. The exported functions are intended to be called by other modules, as well as from within the DLL where they are defined. Internal functions are typically intended to be called only from within the DLL where they are defined. Although a DLL can export data, its data is generally used only by its functions. However, there is nothing to prevent another module from [reading or writing](https://www.mindstick.com/forum/161586/how-do-you-handle-encoding-when-reading-or-writing-to-text-files) that address.

DLLs provide a way to modularize applications so that their functionality can be updated and reused more easily. DLLs also help [reduce memory](https://www.mindstick.com/interview/34250/what-are-some-strategies-to-reduce-memory-usage-in-high-load-dot-net-apps) overhead when several applications use the same functionality at the same time, because although each application receives its own copy of the DLL data, the [applications share](https://www.mindstick.com/interview/22926/how-can-two-android-applications-share-same-linux-user-id-and-share-same-vm) the DLL code.

**Part1: Creating a [Class Library](https://www.mindstick.com/forum/158577/what-is-the-significance-of-the-base-class-library-bcl-in-the-dot-net-framework) (DLL)**

Follow the steps to create an Empty Class [Library Project](https://www.mindstick.com/forum/159156/what-is-the-difference-between-dot-net-core-and-dot-net-standard-class-library-project-types): select **File->New->Project->Visual C# Projects->Class Library**. Select [your project](https://www.mindstick.com/forum/156583/best-way-to-link-bootstrap-file-in-your-project) name and appropriate directory using Browse button and click OK.

**Class1 class**

```
using System;using
System.Collections.Generic;using System.Linq;using System.Text;using
System.Threading.Tasks; namespace stickSum{    public class Class1    {        private bool bTest = false;         public Class1()        {            // // TODO: Add constructor logic here          }         public void sumTest()        {         }        public long sum(long val1, long val2)        {            return val1 + val2;        }         public bool Extra         {            get           
            {                return bTest;            }            set            {                bTest = Extra;            }        }     }}
```

## Part 2: Building a Client Application

Calling methods and properties of a DLL from a C# client is also an easy task. Just follow these few simple steps and see how easy is to create and use a [DLL in C#](https://www.mindstick.com/forum/271/how-can-we-create-dll-in-c-sharp).

Follow the steps to create a [Console Application](https://www.mindstick.com/forum/160510/how-to-fetch-data-from-the-database-in-the-dot-net-console-application-using-c-sharp): select**File->New->Project->Visual C# Projects->Console Application**. I will test my DLL from this console application.

[Add Reference](https://www.mindstick.com/forum/548/how-to-add-reference-to-system-web-optimization) of the Namespace: Now next step is to add reference to the library. You can use Add Reference menu option to add a reference. Go to **Project->Add reference**

Import Namespace, Create Object of class and call its methods and properties.

## RectangleTest class

```
using System;using
System.Collections.Generic;using System.Linq;                                                    using System.Text;using
System.Threading.Tasks;using stickSum; namespace OoopsConcepts{    class RectangleTest    {        static void Main(string[]args)        {                                                                                         Class1 stick = new Class1();            long Res = stick.sum(24, 80);            Console.WriteLine(Res.ToString());            Console.ReadLine();         }    }}
```

**Output:** 104

---

Original Source: https://www.mindstick.com/articles/12038/dll-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
