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()); } }
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()); } }
public DiscJockey(SongsOfThe70s newsongsOfThe70S, SongsOfThe80s newsongsOfThe80S, SongsOfThe90s newsongsOfThe90S) { songsOfThe70S = newsongsOfThe70S; songsOfThe80S = newsongsOfThe80S; songsOfThe90S = newsongsOfThe90S; }
public static void Main() { var songs70s = new SongsOfThe70s(); var songs80s = new SongsOfThe80s(); var songs90s = new SongsOfThe90s(); var madMike = new DiscJockey(songs70s, songs80s, songs90s); madMike.ShowTheSongs(); }