Advertisement
Guest User

Articles 2.0

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