public static void Main() { CustomerCollection cc = new CustomerCollection(); cc.Add(new Customer(98302, "Bob Harroway", "1 NonExistent Place, Chicago", "999-999-9999", new DateTime(1943, 11, 29))); cc.Add(new Customer(12948, "Sarah Fawkes", "3 NonExistent Place, Chicago", "999-999-9992", new DateTime(1967, 2, 3))); cc.Add(new Customer(38291, "Joseph Collins", "11 NonExistent Place, Chicago", "999-999-9991", new DateTime(1979, 8, 15))); cc.Add(new Customer(13849, "Michelle Dover", "16 NonExistent Place, Chicago", "999-999-9985", new DateTime(1952, 12, 27))); cc.Add(new Customer(13849, "Abigail Rivers", "22 NonExistent Place, Chicago", "999-999-9921", new DateTime(1960, 4, 6))); foreach (Customer c in cc) { Console.WriteLine("\r\n------------------"); Console.WriteLine("{0,-20}{1}", "Customer Name:", c.Name); Console.WriteLine("{0,-20}{1}", "Customer ID:", c.Identification); Console.WriteLine("{0,-20}{1}", "Customer Address:", c.Address); Console.WriteLine("{0,-20}{1}", "Customer Phone:", c.Phone); Console.WriteLine("{0,-20}{1}", "Customer Birthday:", c.BirthDate); DateTime dt = new DateTime(c.GetAge().Ticks); Console.WriteLine("{0,-20}{1}", "Customer Age:", dt.Year + " years, " + dt.Day + " days"); } }
public static void Main() { // Make an instance of your new collection CustomerCollection cc = new CustomerCollection(); // Add some objects to it. This is arbitrary information cc.Add(new Customer(98302, "Bob Harroway", "1 NonExistent Place, Chicago", "999-999-9999", new DateTime(1943, 11, 29))); cc.Add(new Customer(12948, "Sarah Fawkes", "3 NonExistent Place, Chicago", "999-999-9992", new DateTime(1967, 2, 3))); cc.Add(new Customer(38291, "Joseph Collins", "11 NonExistent Place, Chicago", "999-999-9991", new DateTime(1979, 8, 15))); cc.Add(new Customer(13849, "Michelle Dover", "16 NonExistent Place, Chicago", "999-999-9985", new DateTime(1952, 12, 27))); cc.Add(new Customer(13849, "Abigail Rivers", "22 NonExistent Place, Chicago", "999-999-9921", new DateTime(1960, 4, 6))); // Loop trhough your colleciton and take appropriate actions // In this example ,we are simply printing the information to the screen foreach (Customer c in cc) { Console.WriteLine("\r\n------------------"); // Format and display the entries Console.WriteLine("{0,-20}{1}", "Customer Name:", c.Name); Console.WriteLine("{0,-20}{1}", "Customer ID:", c.Identification); Console.WriteLine("{0,-20}{1}", "Customer Address:", c.Address); Console.WriteLine("{0,-20}{1}", "Customer Phone:", c.Phone); Console.WriteLine("{0,-20}{1}", "Customer Birthday:", c.BirthDate); DateTime dt = new DateTime(c.GetAge().Ticks); Console.WriteLine("{0,-20}{1}", "Customer Age:", dt.Year + " years, " + dt.Day + " days"); } // Catch input from the user, to ensure the command window stays open Console.WriteLine("\r\n------------------"); Console.WriteLine("Press <Enter> to Finish..."); Console.Read(); }
/// <summary> /// <para> /// Initializes a new instance of <see cref='MySpace.CustomerCollection'/> based on another <see cref='MySpace.CustomerCollection'/>. /// </para> /// </summary> /// <param name='value'> /// A <see cref='MySpace.CustomerCollection'/> from which the contents are copied /// </param> public CustomerCollection(CustomerCollection value) { this.AddRange(value); }
public CustomerEnumerator(CustomerCollection mappings) { this.temp = ((IEnumerable)(mappings)); this.baseEnumerator = temp.GetEnumerator(); }
/// <summary> /// <para> /// Adds the contents of another <see cref='MySpace.CustomerCollection'/> to the end of the collection. /// </para> /// </summary> /// <param name='value'> /// A <see cref='MySpace.CustomerCollection'/> containing the objects to add to the collection. /// </param> /// <returns> /// <para>None.</para> /// </returns> /// <seealso cref='MySpace.CustomerCollection.Add'/> public void AddRange(CustomerCollection value) { for (int i = 0; (i < value.Count); i = (i + 1)) { this.Add(value[i]); } }