global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
Playlist rockPlaylist = new Playlist("My rock playlist");
Song s1 = new Song("Fuel", "Metallica", TimeSpan.FromMinutes(4));
Song s2 = new Song("With or without you", "U2", TimeSpan.FromMinutes(3));
rockPlaylist.AddSong(s1);
rockPlaylist.AddSong(s2);
Playlist pop = new Playlist("Pop of the 90s");
Song s3 = new Song("Torn", "Natalie Imbruglia", TimeSpan.FromMinutes(3));
pop.AddSong(new Song("Hit me baby one more time", "Britney Spears", TimeSpan.FromSeconds(243)));
Console.WriteLine($"Total length of rock playlist: {rockPlaylist.GetTotalLength()}");
Console.WriteLine($"Total length of pop playlist: {pop.GetTotalLength()}");
public string Name { get; }
public string Artist { get; }
public TimeSpan Length { get; }
public Song(string name, string artistName, TimeSpan length)
Console.WriteLine($"Playing song {Name} by {Artist}");
private List<Song> _songs = new List<Song>();
public Playlist(string name)
public void AddSong(Song s)
public void RemoveSong(Song s)
foreach (var song in _songs)
Console.WriteLine($"Song {s.Name} not found in playlist {Name}");
throw new InvalidOperationException("Song not found in playlist");
public TimeSpan GetTotalLength()
TimeSpan totalLength = new TimeSpan();
foreach (var song in _songs)
totalLength += song.Length;
Console.WriteLine($"Playlist: {Name}");
foreach (Song song in _songs)
Console.WriteLine($"- {song.Name} by {song.Artist} ({song.Length})");