Beispiel #1
0
 public List <Music_Info> LoadFromFile(string fileName)
 {
     if (File.Exists(fileName))
     {
         using (StreamReader sr = new StreamReader(fileName, System.Text.Encoding.Default))
         {
             List <Music_Info> list = new List <Music_Info>();
             while (sr.Peek() > -1)
             {
                 string name      = sr?.ReadLine();
                 string performer = sr?.ReadLine();
                 int    year;
                 int.TryParse(sr?.ReadLine(), out year);
                 string album = sr?.ReadLine();
                 sr?.ReadLine();
                 Music_Info tmp = new Music_Info(name, performer, year, album);
                 list.Add(tmp);
             }
             sr.Close();
             return(list);
         }
     }
     else
     {
         throw new Exception("Такого файла не существует");
     }
 }
Beispiel #2
0
        public static void SetComposition(List <Music_Info> list)
        {
            Console.WriteLine("Введите название");
            string name = Console.ReadLine();

            Console.WriteLine("Введите исполнителя");
            string performer = Console.ReadLine();

            Console.WriteLine("Введите год");
            int year;

            int.TryParse(Console.ReadLine(), out year);
            Console.WriteLine("Введите альбом");
            string album = Console.ReadLine();

            Console.ReadLine();
            Music_Info tmp = new Music_Info(name, performer, year, album);

            list.Add(tmp);
        }