class Employee : IClonablePrototype<Employee>
{
string firstName;
string lastName;
public Address Address { get; set; }
public Employee(string firstName, string lastName, Address address)
{
this.firstName = firstName;
this.lastName = lastName;
this.Address = address;
}
public Employee Clone()
{
return base.MemberwiseClone() as Employee;
}
}
public class Address
{
public string Country { get; set; }
public string City { get; set; }
}
static void Main(string[] args)
{
Employee gulizar = new Employee("Gülizar", "Yılmaz", new Address { Country ="Türkiye", City = "İstanbul"});
Employee cloneGulizar = gulizar.Clone();
// Aynı nesne örneklerini farklı referanslarda tutuyor.
// Birbirinin aynısı ve farklı referanslarda olan nesneler elde ettik.
Console.WriteLine(gulizar == cloneGulizar);
Console.WriteLine(gulizar.Address == cloneGulizar.Address);
}
class Employee : IClonablePrototype<Employee>
{
string firstName;
string lastName;
public Address Address { get; set; }
public Employee(string firstName, string lastName, Address address)
{
this.firstName = firstName;
this.lastName = lastName;
this.Address = address;
}
public Employee Clone()
{
Employee employee = base.MemberwiseClone() as Employee;
employee.Address = Address.Clone();
return employee;
}
}
public class Address : IClonablePrototype<Address>
{
public string Country { get; set; }
public string City { get; set; }
public Address Clone()
{
return base.MemberwiseClone() as Address;
}
}