Types of Constructor in C#

Constructor - Constructor is special kind of methods used for initialization of a class.

Types of Constructors
                Default – Without having any parameter
                publicstring fName;
public clsConnect()
        {
            fName = "First Name";
        }
                Parameterized – Constructor at least one parameter
                publicstring fName;
public clsConnect(string sFName)
        {
            fName = sFName;
        }

                Copy – Parameterized constructor that contains a parameter of same class type. The main purpose of this type of constructor is to initialize the new instant to the value of the existing instance.
 publicstring fName;
public clsConnect(string sFName)
        {
            fName = sFName;
        }

public clsConnect(clsConnect objCon)
        {
            fName = objCon.fName;
        }
                Static–used to initialize the static data members of the class. It only called once while creation of the first instance of the class.
staticstring fName;
static clsConnect()
        {
            fName = "First Name";
        }
                Private – You cannot create the instance of private constructor class.
private clsConnect()
        {

        }

Comments

Popular posts from this blog

SSIS Merge Join - Both inputs of the transformation must contain at least one sorted column, and those columns must have matching metadata SSIS

jsGrid

Web scraping through WebBrowser (.Net WinForm Control)