When an object created with new key word, while creating an instance of a class, a special method called constructor is summoned to facilitate the object manipulation. If we don't create constructor, C# and other advance compilers will create a default constructor for you. Constructors are
  • can work like a method.
  • may or may not be parameterized
  • destructor's name should match the class name
The example shown below does not have Main entry point, because I am going to use it as dll in many other examples. The take home message of this example is to introduce the concept of constructor and destructor. A constructor or destructor will have the same name of the class, and compiler will know for sure that a class of "xyz" exists.
//------this one will not compile------
//Compilation is done using "csc /target:library contructor_dll.cs "
using System;
//UseName.cs is the file which uses this dll.
namespace DllCon
public class add_different
// this one will not compile
public add() { Console.WriteLine("Constructor evoked"); }
~add() { Console.WriteLine("Destructor evoked"); }
public int bonus(int b, int a)
int n = a + b ;

Console.WriteLine("Hi,Your Total Sal is" + n + " this returns through dll");
return n;

For a compiled version please review these examples. 1, 2, 3