using System.Collections.Generic;
public string Title { get; set; }
public string Author { get; set; }
public string ISBN { get; set; }
public int Year { get; set; }
public Book(string title, string author, string isbn, int year)
Console.WriteLine("Title: {Title}, Author: {Author}, ISBN: {ISBN}, Year: {Year}");
public List<Book> Books { get; set; }
Books = new List<Book>();
public void AddBook(Book book)
public Book SearchBookByTitle(string title)
foreach (var book in Books)
if (book.Title.ToLower() == title.ToLower())
public void LoadBooksFromFile(string filePath)
using (StreamReader reader = new StreamReader(filePath))
while ((line = reader.ReadLine())!= null)
string[] parts = line.Split(' ');
Book book = new Book(parts[0], parts[1], parts[2], int.Parse(parts[3]));
Console.WriteLine("Грешка при зареждане на книги от файл: " + ex.Message);
static void Main(string[] args)
Library library = new Library();
Console.WriteLine("Меню:");
Console.WriteLine("1. Добави книга ръчно");
Console.WriteLine("2. Зареди книги от файл");
Console.WriteLine("3. Търси книга по заглавие");
Console.WriteLine("4. Изход");
int choice = int.Parse(Console.ReadLine());
Console.Write("Въведете заглавие: ");
string title = Console.ReadLine();
Console.Write("Въведете автор: ");
string author = Console.ReadLine();
Console.Write("Въведете ISBN: ");
string isbn = Console.ReadLine();
Console.Write("Въведете година: ");
int year = int.Parse(Console.ReadLine());
Book book = new Book(title, author, isbn, year);
Console.Write("Въведете пътя до файла: ");
string filePath = Console.ReadLine();
library.LoadBooksFromFile(filePath);
Console.Write("Въведете заглавие за търсене: ");
string searchTitle = Console.ReadLine();
Book foundBook = library.SearchBookByTitle(searchTitle);
Console.WriteLine("Книгата не е намерена.");
Console.WriteLine("Невалиден избор.");
public static void Main()
Console.WriteLine("Hello World");