Cyclic Constructor in Class Creation Csharp

Cyclic Constructor :


We have various type of constructor and cyclic constructor is one of the type. It is inherited constructor within a class so as to avoid redundant constructor's parameter in class object.
Type Of constructors Are:

-Default Constructor
-Parameterized Constructor
-Static Constructor
-Copy Constructor
-Private Constructor(Singleton pattern)
-Cyclic Constructor


public class Car
{
//Private Member
private int m_CarID=int.MinValue;
private string m_CarType=string.Empty;
private string m_CarName=string.Empty;
private string m_Color=string.Empty;
private string m_Model=string.Empty;

//Constructor
public Car()
{
//default Constructor
}

//Parameterized Constructor
public Car(int carID, string carName)
{
m_CarID = carID;
m_CarName = carName;
}

//Cyclic Constructor
public Car(int carID, string carName, string carType,string carModel):this(carID,carName)
{
m_CarType = carType;
m_Model = carModel;
}

//Cyclic Constructor
public Car(int carID, string carName, string carType, string carModel,string color)
: this(carID, carName,carType,carModel)
{
m_Color = color;
}
}

static void main()
{
Car objCarA=new Car();
Car objCarB=new Car(1,"matiz");
Car objCarC=new Car(1,"matiz","SmallCar","2000");
Car objCarD=new Car(1,"matiz","SmallCar","2000","Dark Green");
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: