Here, I have created two classes Program in which Main() is present and Customer Class in which I have two Customer class constructors 1. without arguments 2. with arguments. How can i call the two constructors using single instance C1 of Customer class created in Main?
using System;
public class Program
{
public static void Main()
{
Customer C1 = new Customer();
C1.PrintFullName();
C1 = new Customer();
C1.PrintFullName();
}
}
class Customer
{
string _firstName;
string _lastName;
public Customer() : this("No firstname","No lastname")
{
}
public Customer(string FirstName, string LastName)
{
this._firstName = FirstName;
this._lastName = LastName;
}
public void PrintFullName()
{
Console.WriteLine("Full Name is {0}", this._firstName+" "+this._lastName);
}
}
: this("No firstname","No lastname"), so you're already executing the code of both constructors. What are you trying to achieve?