I wrote a CustomerCollection class that implements the IEnumerable and IEnumerator interfaces. Now I want the CustomerCollection class object to be searchable by the Where () And Find () function, and also want to get a List object of type Customer from the CustomerCollection class. Please help. In addition, the correct implementation of the interfaces.
public class Customer { private int _CustomerID; private string _CustomerName; public Customer(int customerID) { this._CustomerID = customerID; } public int CustomerID { get { return _CustomerID; } set { _CustomerID = value; } } public string CustomerName { get { return _CustomerName; } set { _CustomerName = value; } } } public class CustomerController { public ArrayList PopulateCustomer() { ArrayList Temp = new ArrayList(); Customer _Customer1 = new Customer(1); Customer _Customer2 = new Customer(2); _Customer1.CustomerName = "Soham Dasgupta"; _Customer2.CustomerName = "Bappa Sarkar"; Temp.Add(_Customer1); Temp.Add(_Customer2); return Temp; } } public class CustomerCollection : IEnumerable, IEnumerator { ArrayList Customers = null; IEnumerator CustomerEnum = null; public CustomerCollection() { this.Customers = new CustomerController().PopulateCustomer(); this.CustomerEnum = Customers.GetEnumerator(); } public void SortByName() { this.Reset(); } public void SortByID() { this.Reset(); } public IEnumerator GetEnumerator() { return (IEnumerator)this; } IEnumerator IEnumerable.GetEnumerator() { return (IEnumerator)this; } public void Reset() { CustomerEnum.Reset(); } public bool MoveNext() { return CustomerEnum.MoveNext(); } public object Current { get { return (Customer)CustomerEnum.Current; } } }
source share