Advertisement
gospod1978

Object and Class/Songs

Oct 24th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.Numerics;
  6.  
  7.  
  8. namespace fundamental14
  9. {
  10.     class Song
  11.     {
  12.         public string TypeList { get; set; }
  13.         public string Name { get; set; }
  14.         public string Time { get; set; }
  15.     }
  16.  
  17.     class MainClass
  18.     {
  19.         public static void Main()
  20.         {
  21.             int numSong = int.Parse(Console.ReadLine());
  22.             List<Song> songs = new List<Song>();
  23.             for (int i = 0; i < numSong; i++)
  24.             {
  25.                 string[] data = Console.ReadLine().Split("_");
  26.                 string type = data[0];
  27.                 string name = data[1];
  28.                 string time = data[2];
  29.                 Song song = new Song();
  30.                 song.TypeList = type;
  31.                 song.Name = name;
  32.                 song.Time = time;
  33.                 songs.Add(song);
  34.             }
  35.             string typeList = Console.ReadLine();
  36.             if (typeList == "all")
  37.             {
  38.                 foreach (Song song in songs)
  39.                 {
  40.                     Console.WriteLine(song.Name);
  41.                 }
  42.             }
  43.             else
  44.             {
  45.                 List<Song> filteredSong = songs.Where(s => s.TypeList == typeList).ToList();
  46.  
  47.                 foreach (Song song in filteredSong)
  48.                 {
  49.                     Console.WriteLine(song.Name);
  50.                 }
  51.             }
  52.  
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement