درود بر تمامی برنامه نویسان ایران زمین امروز ، مبحث Constructor Chaining در سی شارپ رو براتون قرار دادم.انشاالله که این آموزش به دردتون بخوره و مورد استفاده قرارش بدین.
این هم کد برنامه:
namespace ConstructorChaining
{
class Employee
{
public string FirstName { get; private set; }
public string LastName { get; private set; }
public Employee()
{
this.FirstName = "Akshay";
this.LastName = "Patel";
}
public Employee(string firstName)
{
this.FirstName = firstName;
}
public Employee(string firstName, string lastName) : this(firstName)
{
this.LastName = lastName;
}
}
}
Client:
namespace ConstructorChaining
{
class Program
{
static void Main(string[] args)
{
Employee emp2 = new Employee("Ishu", "Patel");
Console.WriteLine(emp2.FirstName + " " + emp2.LastName);
Console.ReadKey();
}
}
}
{
class Employee
{
public string FirstName { get; private set; }
public string LastName { get; private set; }
public Employee()
{
this.FirstName = "Akshay";
this.LastName = "Patel";
}
public Employee(string firstName)
{
this.FirstName = firstName;
}
public Employee(string firstName, string lastName) : this(firstName)
{
this.LastName = lastName;
}
}
}
Client:
namespace ConstructorChaining
{
class Program
{
static void Main(string[] args)
{
Employee emp2 = new Employee("Ishu", "Patel");
Console.WriteLine(emp2.FirstName + " " + emp2.LastName);
Console.ReadKey();
}
}
}
موفق باشید.