What is constructor chaining?

 Posted by Rajni.Shekhar on 4/9/2012 | Category: C# Interview questions | Views: 2424 | Points: 40

Constructor Chaining is used to call a constructor in another constructor. Means you can initialize some fields using another constructor in one constructor.


Public class Example{
string strName;
string strCity;

public Example(string Name, string City)
this.strName = FirstName;
this.strCity = City;
//another constructor
public Example(string Name):this(Name,"Delhi")
this.strName= FName;

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response