Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // The following manually implements IEnumerable in order to create a new enumerator.
            Console.WriteLine("SportCollection contents:");
            SportCollection sportCollection = new SportCollection();
            foreach (Sport sport in sportCollection)
            {
                Console.WriteLine(sport.ToString());
            }

            Console.WriteLine();
            Console.WriteLine("SportCollection contents:");
            SportCollectionYieldReturn sportCollectionYieldReturn = new SportCollectionYieldReturn();
            foreach (Sport sport in sportCollectionYieldReturn)
            {
                Console.WriteLine(sport.ToString());
            }

            Console.WriteLine();
            IEnumerable<string> names = NameEnumerator(); // Put a breakpoint here
            foreach (string name in names)
                Console.WriteLine(name);

            // Use the Guy's indexer
            Console.WriteLine("Adding two guys and modifying one guy");
            GuyCollection guyCollection = new GuyCollection();

            // Update one guy's age
            guyCollection["Bob"] = guyCollection["Joe"] + 3;

            // Add two more guys
            guyCollection["Bill"] = 57;
            guyCollection["Harry"] = 31;

            foreach (Guy guy in guyCollection)
            {
                Console.WriteLine(guy.ToString());
            }

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine();

            Console.WriteLine("ManualSportCollection contents:");
            ManualSportCollection manualSportCollection = new ManualSportCollection();
            foreach (Sport sport in manualSportCollection)
                Console.WriteLine(sport.ToString());

            Console.WriteLine();

            Console.WriteLine("SportCollection contents:");
            SportCollection sportCollection = new SportCollection();
            foreach (Sport sport in sportCollection)
                Console.WriteLine(sport.ToString());

            Console.WriteLine();

            Console.WriteLine(sportCollection[3]);

            Console.WriteLine();

            IEnumerable<string> names = NameEnumerator(); // Put a breakpoint here
            foreach (string name in names)
                Console.WriteLine(name);

            Console.WriteLine();

            Console.WriteLine("Adding two guys and modifying one guy");
            GuyCollection guyCollection = new GuyCollection();
            guyCollection["Bob"] = guyCollection["Joe"] + 3;
            guyCollection["Bill"] = 57;
            guyCollection["Harry"] = 31;
            foreach (Guy guy in guyCollection)
                Console.WriteLine(guy.ToString());

            Console.ReadKey();
        }