How to Create Dll

Component--> A component is reusable piece of code and is in the form of DLL.

Once component is designed it can be reused from any kind of application like in console application or windows application or web application or device application etc.

Once a component is designed in any programming language of .net that can be reused from any other programming languages of .Net i.e. .Net components are or assemblies will provide language interoperability.

To create component in .Net, we use class libraries templates. End user will never interact with some application will interact with component or DLL.

Program for creating a Component / Assembly,
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. namespace CLibMaths   
  6. {  
  7.     public class Arithmatic   
  8.     {  
  9.         public int Num1, Num2, Result;  
  10.         public int PNum1   
  11.         {  
  12.             set {  
  13.                 Num1 = value;  
  14.             }  
  15.             get {  
  16.                 return Num1;  
  17.             }  
  18.         }  
  19.         public int PNum2 {  
  20.             set {  
  21.                 Num2 = value;  
  22.             }  
  23.         }  
  24.         public int PResult {  
  25.             get {  
  26.                 return Result;  
  27.             }  
  28.         }  
  29.         public int Add() {  
  30.             Result = Num1 + Num2;  
  31.             return Result;  
  32.         }  
  33.         public void Subtract() {  
  34.             Result = Num1 - Num2;  
  35.         }  
  36.         public void Multiply() {  
  37.             Result = Num1 * Num2;  
  38.         }  
  39.         public void Divide() {  
  40.             Result = Num1 / Num2;  
  41.         }  
  42.     }  
  43. }  
ADD a new class with name ClsMathNumbers, Change the accessibility of the class to public and write following code,
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. namespace CLibMaths   
  6. {  
  7.     public class ClsMathNumbers   
  8.     {  
  9.         public int Square(int x)  
  10.         {  
  11.             return x * x;  
  12.         }  
  13.         public int Cube(int x)  
  14.         {  
  15.             return x * Square(x);  
  16.         }  
  17.         public int Factorial(int x)  
  18.         {  
  19.             int R = 1;  
  20.             for (int i = 1; i <= x; i++)  
  21.             {  
  22.                 R = R * i;  
  23.             }  
  24.             return R;  
  25.         }  
  26.     }  
  27. }  
Build the solution will create a DLL. this dll is known as .net component to see the DLL go to the \bin\Debug folder of the application , you find the CLibMaths.dll.