public object Clone() { People ClonedPeople = new People(); Person currentPerson, newPerson; foreach (DictionaryEntry p in Dictionary) { currentPerson = p.Value as Person; newPerson = new Person(); newPerson.Name = currentPerson.Name; newPerson.Age = currentPerson.Age; ClonedPeople.add(newPerson); } return ClonedPeople; }
//Other Methods public Person[] GetOldest() { Person oldestPerson = null; People oldestPeople = new People(); Person currentPerson; foreach (DictionaryEntry p in Dictionary) { currentPerson = p.Value as Person; if (oldestPerson == null) { oldestPerson = currentPerson; oldestPeople.add(oldestPerson); } else { if (currentPerson > oldestPerson) { oldestPeople.Clear(); oldestPeople.add(currentPerson); oldestPerson = currentPerson; } else { if (currentPerson >= oldestPerson) { oldestPeople.add(currentPerson); } } } } Person[] oldestPeopleArray = new Person[oldestPeople.Count]; int copyIndex = 0; foreach (DictionaryEntry p in oldestPeople) { oldestPeopleArray[copyIndex] = p.Value as Person; copyIndex++; } return oldestPeopleArray; }