Advertisement
Guest User

03. Articles 2.0

a guest
Jun 27th, 2019
1,364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace _03._Articles_2._0
  5. {
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             int countArticles = int.Parse(Console.ReadLine());
  11.  
  12.             List<Article> articles = new List<Article>();
  13.  
  14.             string[] input;
  15.  
  16.             for (int i = 0; i < countArticles; i++)
  17.             {
  18.                 input = Console.ReadLine().Split(", ");
  19.  
  20.                 var article = new Article(input[0], input[1], input[2]);
  21.  
  22.                 articles.Add(article);
  23.  
  24.             }
  25.  
  26.             string orderByWhat = Console.ReadLine();
  27.  
  28.             switch (orderByWhat)
  29.             {
  30.                 case "title":
  31.                     articles = articles.OrderBy(X => X.Title).ToList();
  32.                     break;
  33.  
  34.                 case "content":
  35.                     articles = articles.OrderBy(X => X.Content).ToList();
  36.                     break;
  37.  
  38.                 case "autor":
  39.                     articles = articles.OrderBy(X => X.Author).ToList();
  40.                     break;
  41.             }
  42.  
  43.             Console.WriteLine(string.Join(Environment.NewLine, articles));
  44.         }
  45.     }
  46.  
  47.     class Article
  48.     {
  49.         public string Title { get; set; }
  50.         public string Content { get; set; }
  51.         public string Author { get; set; }
  52.  
  53.         public Article(string title, string content, string autor)
  54.         {
  55.             Title = title;
  56.             Content = content;
  57.             Author = autor;
  58.         }
  59.  
  60.         public override string ToString()
  61.         {
  62.             return $"{Title} - {Content}: {Author}";
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement