Exemplo n.º 1
0
    void Start( )
    {
        // creating the collections and adding some songs:
        SongsOfThe70s song70s = new SongsOfThe70s();

        song70s.AddSong("song title", "song artist", 1974);
        song70s.AddSong("song title2", "song artist2", 1978);

        SongsOfThe80s song80s = new SongsOfThe80s();

        song80s.AddSong("song title 80s", "song artist 80s", 1985);
        song80s.AddSong("song title2 80s", "song artist2 80s", 1989);

        // because of the iterator pattern we can loop through both types
        // of collections the same simple way and don't have to bother
        // with what type of collection the object stores:

        IEnumerator songsOfThe70sIterator = song70s.GetIterator();

        while (songsOfThe70sIterator.MoveNext())
        {
            SongInfo info = (SongInfo)songsOfThe70sIterator.Current;
            Debug.Log("Song 70s: " + info.ToString());
        }

        IEnumerator songsOfThe80sIterator = song80s.GetIterator();

        while (songsOfThe80sIterator.MoveNext())
        {
            SongInfo info = (SongInfo)songsOfThe80sIterator.Current;
            Debug.Log("Song 80s: " + info.ToString());
        }
    }
Exemplo n.º 2
0
        void Start()
        {
            SongsOfThe70s song70s = new SongsOfThe70s();

            song70s.AddSong("song title", "song artist", 1974);
            song70s.AddSong("song title2", "song artist2", 1978);

            IEnumerator songsOfThe70sIterator = song70s.GetIterator();

            while (songsOfThe70sIterator.MoveNext())
            {
                SongInfo info = (SongInfo)songsOfThe70sIterator.Current;
                Debug.Log("Song 70s: " + info.ToStringEx());
            }

            SongsOfThe80s song80s = new SongsOfThe80s();

            song80s.AddSong("song title 80s", "song artist 80s", 1985);
            song80s.AddSong("song title2 80s", "song artist2 80s", 1989);
            IEnumerator songsOfThe80sIterator = song80s.GetIterator();

            while (songsOfThe80sIterator.MoveNext())
            {
                SongInfo info = (SongInfo)songsOfThe80sIterator.Current;
                Debug.Log("Song 80s: " + info.ToStringEx());
            }
        }