Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'          collections/collection/1/prog.cs - A sample client of AnimalFarm.Lecture 12 - slide 11 : 36
Program 3

using System;
using System.Collections.ObjectModel;

class App{

  public static void Main(){

    AnimalFarm af = new AnimalFarm();

    // Populating the farm with Add
    af.Add(new Animal("elephant"));
    af.Add(new Animal("giraffe"));
    af.Add(new Animal("tiger"));
    ReportList("Adding elephant, giraffe, and tiger with Add(...)", af);

    // Additional population with Insert
    af.Insert(0, new Animal("blueJay", AnimalGroup.Bird));
    af.Insert(0, new Animal("goldenEagle", AnimalGroup.Bird));
    ReportList("Inserting blue jay and golden eagle at index 0 with Insert(0, ...)", af);

    // Extract birds:
    AnimalFarm birds = af.GetGroup(AnimalGroup.Bird);
    ReportList("The birds in farm - extraced with GetGroup", birds);

    // Remove tiger
    af.Remove(new Animal("tiger"));
    ReportList("Removing tiger with Remove(...)", af);

    // Remove animal at index 2
    ReportList("Removing animal at index 2, with RemoveAt(2)", af);

    // Clear the farm
    ReportList("Clear the farm with Clear()", af);

  public static void ReportList<T>(string explanation, Collection<T> list){
    foreach(T el in list)
      Console.WriteLine("{0, 3}", el);
    Console.WriteLine(); Console.WriteLine();