How to Create a C# DLL file using Visual Studio 2010

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saikat bose
    New Member
    • Nov 2011
    • 1

    How to Create a C# DLL file using Visual Studio 2010

    We create our c# dll file using the visual studio 2010.

    So first from file menu select the project option, then
    select the class library,named it as you wish after cliking ok by default a classlibrary1 has created and inside that a class1 also created.

    Inside this class1 you should placed your methods which you wish to use in other project files. After creating the class you should build it.To build it you must save the file first then from build menu select build> build classlibrary1.

    After a successful build,you close this file, and open a new project where you wish to use this dll. From the project menu select add reference,the add reference window will shown , then choose the browse button and browse the dll file where you store it for example-> projects->classlibrary 1->bin->debug or bin->release and locate the dll file. Now you able to use it in your project.

    You must call the namespace, to use the methods inside the dll.( using namespace_name; )

    Here we use the createdll the dll file
    Code:
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using createdll;
    namespace WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                try
                {
                    long a, b;
                    a = long.Parse(textBox1.Text);
                    b = long.Parse(textBox2.Text);
                    textBox3.Text = math.add(a, b).ToString();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
    }
    Here a simple example of class inside the dll file.
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ClassLibrary1
    {
        public class Class1
        {
            public static long add(long a, long b)
            {
                return (a + b);
            }
        }
    }

    Note: After successful build of this class will create a dll file( here ut ClassLibrary1.d ll
    Last edited by MMcCarthy; Nov 17 '11, 11:08 PM. Reason: adding code tags and formatting
  • jonasstuart
    New Member
    • Sep 2016
    • 2

    #2
    Thanks Buddy to sharing very informative post. I would like to appreciate you for sharing this post.I have found another nice post related to this post over the internet which also explained very well. Check this.Creating C# Class Library (DLL)

    Comment

    Working...