blog

Home / DeveloperSection / Blogs / Creating dll in c#.

Creating dll in c#.

Anonymous User7359 13-Jun-2011

In this blog, I will tell you that how to create dll in c# by using notepad and visual studio command prompt. Here I will provide you a sample algorithm which is helpful for you while creating dll in c#.

1)      Create a class for which you want to create a dll. Like following example will be demonstrate a sample class.


/*
     This is a program which give you a demonstration that how to
   make a dll in c# using notepad and visual studio command prompt.
*/
using System;   //A basic namespace which is required for c# program.
public class Employee
{
     public void disp()
     {
    Console.WriteLine("This is sample dll created by notepad and c# compiler.");
       }        

2)      Save this class in a file by using valid filename. I had save this file by using Employee.cs for this demonstration.

3)      Now compile this file by using following syntax.

               csc  /target:library Employee.cs

  This will create a dll for Employee class. Here target:library will denotes that a dll should be      created after compilation.

4)      Now create another file in which create a TestEmployee named class which used this dll. Following example will demonstrate use of this class.

/*
                This is a sample program which will execute
                Employee.dll
*/
using System;
public class TestEmployee
{
                public static void Main()
                {
                                Console.WriteLine("Testing of Employee.dll begins....");
                                Employee emp=new Employee();   //Create an object of Employee class.
                                emp.disp();                    //Call disp() method of Employee class.
                                Console.WriteLine("Testing of Employee.dll ends....");
                }

5)      Save this file by using TestEmployee.cs .

6)      Compile this file by using following syntax.

 csc  /reference:Employee.dll  TestEmployee.cs

Here reference word tells that Employee.dll is added in program before compiling.

7)      Now execute program by writing TextEmployee.exe and see the output.


Updated 18-Sep-2014
I am a content writter !

Leave Comment

Comments

Liked By