Array.Clone
using System;
using System.Collections.Generic;
public class Starter {
public static void Main() {
CommissionedEmployee[] salespeople =
{new CommissionedEmployee("Bob"),
new CommissionedEmployee("Ted"),
new CommissionedEmployee("Sally")};
Employee[] employees =
(Employee[])salespeople.Clone();
foreach (Employee person in
employees) {
person.Pay();
}
}
}
public class Employee {
public Employee(string name) {
m_Name = name;
}
public virtual void Pay() {
Console.WriteLine("Paying {0}", m_Name);
}
private string m_Name;
}
public class CommissionedEmployee : Employee {
public CommissionedEmployee(string name) :
base(name) {
}
public override void Pay() {
base.Pay();
Console.WriteLine("Paying commissions");
}
}
Related examples in the same category