public void AddRange(EmployeeCollection collection) { for (int i = 0; i < collection.Count; i++) { this.List.Add(collection[i]); } }
static void Main(string[] args) { Employee emp1 = new Employee { Name = "A", Age = 20 }; Employee emp2 = new Employee { Name = "B", Age = 20 }; Employee emp3 = new Employee { Name = "C", Age = 20 }; Employee emp4 = new Employee { Name = "D", Age = 20 }; EmployeeCollection collection = new EmployeeCollection(); collection.Add(emp1); collection.Add(emp2); collection.Add(emp3); collection.Add(emp4); collection.Remove(emp4); Console.WriteLine("Without using custom enumerator"); foreach (Employee item in collection) { Console.WriteLine(item.Name); } Console.WriteLine("Using custom enumerator"); foreach (Employee item in collection.GetEmployeeEnumerator()) { Console.WriteLine(item.Name); } Console.ReadKey(); }
public EmployeeEnumerator(EmployeeCollection _collection) { collection = _collection; }