TheBulgarianWolf

Article 2.0

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