Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Object_and_Clasess
- {
- class Program
- {
- static void Main()
- {
- int count = int.Parse(Console.ReadLine());
- List<Article> list = new List<Article>();
- for (int i = 0; i < count; i++)
- {
- string[] tokens = Console.ReadLine().Split(',');
- Article myArticle = new Article(tokens[0], tokens[1], tokens[2]);
- list.Add(myArticle);
- }
- string criteria = Console.ReadLine();
- List<Article> sortedArticles = new List<Article>();
- if (criteria == "title")
- {
- sortedArticles = list.OrderBy(a => a.Title).ToList();
- }
- else if (criteria == "content")
- {
- sortedArticles = list.OrderBy(a => a.Content).ToList();
- }
- else
- {
- sortedArticles = list.OrderBy(a => a.Author).ToList();
- }
- sortedArticles.ForEach(x => Console.WriteLine(x));
- }
- class Article
- {
- public string Title { get; set; }
- public string Content { get; set; }
- public string Author { get; set; }
- public Article(string title, string content, string author)
- {
- Title = title;
- Content = content;
- Author = author;
- }
- public override string ToString()
- {
- return $"{Title} -{Content}:{Author}";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment