Exercises


  1. Create a collection class called People that is a collection of the Person class shown below. The items in the collection should be accessible via a string indexer that is the name of the person, identical to the Person.Name property:

     public class Person { private string name; private int age; public string Name { get { return name; } set { name = value; } } public int Age { get { return age; } set { age = value; } } } 
  2. Extend the Person class from the preceding exercise so that the >, <, >=, and <= operators are overloaded, and compare the Age properties of Person instances.

  3. Add a GetOldest() method to the People class that returns an array of Person objects with the greatest Age property (1 or more objects, as multiple items may have the same value for this property), using the overloaded operators defined above.

  4. Implement the ICloneable interface on the People class to provide deep copying capability.

  5. Add an iterator to the People class that enables you to get the ages of all members in a foreach loop as follows:

     foreach (int age in myPeople.Ages) { // Display ages. } 




Beginning Visual C# 2005
Beginning Visual C#supAND#174;/sup 2005
ISBN: B000N7ETVG
EAN: N/A
Year: 2005
Pages: 278

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net