---
title: "Creating C# Class Library (DLL) Using Visual Studio .NET"  
description: "Creating C# Class Library in Visual Studio .NET is an easy way. Here I have described, How to create DLL in Visual Studio and"  
author: "AVADHESH PATEL"  
published: 2012-08-16  
updated: 2020-07-24  
canonical: https://www.mindstick.com/articles/980/creating-c-sharp-class-library-dll-using-visual-studio-dot-net  
category: ".net"  
tags: [".net"]  
reading_time: 2 minutes  

---

# Creating C# Class Library (DLL) Using Visual Studio .NET

## Creating C# Class Library (DLL) Using Visual Studio .NET

First of all, Creating C# [Class Library](https://www.mindstick.com/forum/158577/what-is-the-significance-of-the-base-class-library-bcl-in-the-dot-net-framework) in Visual Studio .NET is an easy way. Here I have described, How to create DLL in [Visual Studio and](https://www.mindstick.com/articles/618/create-microsoft-word-document-by-using-c-sharp) How to access this DLL in our project. Here I used Visual Studio 2010.\

##### Steps for Creating DLL

**Step 1:-** **File->New->Project->Visual [C# Projects](https://answers.mindstick.com/qa/93921/what-are-the-uses-of-partial-class-and-methods-in-c-sharp-and-why-are-use-in-c-sharp-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 click OK

![Creating C# Class Library (DLL) Using Visual Studio .NET](https://www.mindstick.com/mindstickarticle/9c667330-0966-4e38-a689-61fed9cbbb4c/images/c38dad8a-1299-4f69-925b-4a4f6df308bf.png)\

After Clicking on button ‘OK’, solution explorer adds one C# class ‘Class1.cs’. In this class, we can write our code.

![Creating C# Class Library (DLL) Using Visual Studio .NET](https://www.mindstick.com/mindstickarticle/9c667330-0966-4e38-a689-61fed9cbbb4c/images/d1f320b8-c93e-485c-9b94-b636cb9c9808.png)\

When we [double click](https://www.mindstick.com/forum/156225/differentiate-between-google-adword-and-double-click) on Class1.cs, we see a [namespace](https://www.mindstick.com/articles/28/namespace-in-dot-net) CreatingDLL. We will be using this namespace in our project to access this class library.

![Creating C# Class Library (DLL) Using Visual Studio .NET](https://www.mindstick.com/mindstickarticle/9c667330-0966-4e38-a689-61fed9cbbb4c/images/178431e2-0da1-4961-a2d9-7cec4a51f4c8.png)

**Step 2:-** Within Class1.cs we create a method named ‘sum’ that takes two integers value and returns the sum to which method passed numbers.

```
using System;namespace CreatingDLL{    public class Class1    {        /// <summary>        /// sum is method that take two integer value and return that sum        /// </summary>        /// <param name="x"></param>        /// <param name="y"></param>        /// <returns></returns>        public int sum(int x, int y)        {            return x + y;        }    }} 
```

**Step 3:-** Now build the Application and see the bin\debug directory of our project. ‘CreatingDLL.dll’ is created. Now we create another application and take this DLL (CreatingDLL.dll) reference for accessing DLL’s method.

##### Steps for Accessing Created DLL

**Step 4:-** File->New->Project->Visual C# Projects->Windows [Form Application](https://www.mindstick.com/forum/34200/system-data-sqlclient-sqlexception-occurred-while-using-checked-or-radio-button-in-form-application).

**Step 5:-** Designed windows form as a bellow figure.

![Creating C# Class Library (DLL) Using Visual Studio .NET](https://www.mindstick.com/mindstickarticle/9c667330-0966-4e38-a689-61fed9cbbb4c/images/a2470046-e80f-43e5-97c9-28299eafb7f7.png)\

**Step 6:-** [Add reference](https://www.mindstick.com/forum/548/how-to-add-reference-to-system-web-optimization) of DLL (CreatingDLL) which we created before few minutes.

\
![Creating C# Class Library (DLL) Using Visual Studio .NET](https://www.mindstick.com/mindstickarticle/9c667330-0966-4e38-a689-61fed9cbbb4c/images/892ba167-6395-4e3c-a3d0-8c8c2ee0623b.png)\

![Creating C# Class Library (DLL) Using Visual Studio .NET](https://www.mindstick.com/mindstickarticle/9c667330-0966-4e38-a689-61fed9cbbb4c/images/4abf20b4-2eea-4b17-8ee2-52007d0f960b.png)

After adding reference of DLL, following windows will appear.

\
![Creating C# Class Library (DLL) Using Visual Studio .NET](https://www.mindstick.com/mindstickarticle/9c667330-0966-4e38-a689-61fed9cbbb4c/images/a1554eb2-60bd-419d-851d-53b34c523027.png)\

**Step 7:-** Write code on [button click](https://www.mindstick.com/forum/568/check-condion-before-post-page-on-button-click-in-jquery-or-javascript) of Windows Form Application. Before creating an object and making the method of Add DLL, add namespace CreatedDLL in the project as bellow code.

```
using System;using System.Windows.Forms;using CreatingDLL;namespace AccessingDLL{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }         private void btnAdd_Click(object sender, EventArgs e)        {            Class1 c1 = new Class1();            try            {                txtResult.Text
= Convert.ToString(c1.sum(Convert.ToInt32(txtNumber1.Text), Convert.ToInt32(txtNumber2.Text)));            }            catch(Exception ex)            {                MessageBox.Show(ex.Message);            }        }    }} 
```

**Step 8:-** Now build the application and execute the project and see the output.

![Creating C# Class Library (DLL) Using Visual Studio .NET](https://www.mindstick.com/mindstickarticle/9c667330-0966-4e38-a689-61fed9cbbb4c/images/3fc56c9a-1659-4f9b-8417-e7cd4b6196c4.png)\

---

Original Source: https://www.mindstick.com/articles/980/creating-c-sharp-class-library-dll-using-visual-studio-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
