User Defined Class Libraries or Dlls

Once a 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 it can be reused from any other programming languages of .Net; i.e., .Net components or assemblies will provide language interoperability.
To create components in .Net, we use class library templates.

End user will never interact with some applications; but will interact with components 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.             return x * x;  
  11.         }  
  12.         public int Cube(int x) {  
  13.             return x * Square(x);  
  14.         }  
  15.         public int Factorial(int x) {  
  16.             int R = 1;  
  17.             for (int i = 1; i <= x; i++) {  
  18.                 R = R * i;  
  19.             }  
  20.             return R;  
  21.         }  
  22.     }  
  23. }  
Building 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.
Ebook Download
View all
Learn
View all