C# programlama dilinde örnek bir proje.
using System;
using System.Collections.Generic;
using System.Linq;
namespace LibraryManagementSystem
{
class Program
{
static List<Book> library = new List<Book>();
static void Main(string[] args)
{
Console.WriteLine("=== Kütüphane Yönetim Sistemi ===");
while (true)
{
Console.WriteLine("\nSeçenekler:");
Console.WriteLine("1 - Kitap Ekle");
Console.WriteLine("2 - Kitapları Listele");
Console.WriteLine("3 - Kitap Ara");
Console.WriteLine("4 - Çıkış");
Console.Write("Seçiminizi yapın: ");
string choice = Console.ReadLine();
switch (choice)
{
case "1":
AddBook();
break;
case "2":
ListBooks();
break;
case "3":
SearchBook();
break;
case "4":
Console.WriteLine("Programdan çıkılıyor...");
return;
default:
Console.WriteLine("Geçersiz seçim! Tekrar deneyin.");
break;
}
}
}
static void AddBook()
{
Console.WriteLine("\nKitap Ekleme");
Console.Write("Kitap Adı: ");
string title = Console.ReadLine();
Console.Write("Yazar Adı: ");
string author = Console.ReadLine();
Console.Write("Yayın Yılı: ");
int year;
while (!int.TryParse(Console.ReadLine(), out year) || year < 0)
{
Console.Write("Geçerli bir yıl girin: ");
}
Book newBook = new Book { Title = title, Author = author, Year = year };
library.Add(newBook);
Console.WriteLine($"'{title}' adlı kitap başarıyla eklendi.");
}
static void ListBooks()
{
Console.WriteLine("\nKütüphanedeki Kitaplar:");
if (library.Count == 0)
{
Console.WriteLine("Henüz eklenmiş kitap yok.");
return;
}
int count = 1;
foreach (var book in library)
{
Console.WriteLine($"{count++}. {book.Title} - {book.Author} ({book.Year})");
}
}
static void SearchBook()
{
Console.Write("\nAramak istediğiniz kitabın adını yazın: ");
string searchQuery = Console.ReadLine().ToLower();
var searchResults = library.Where(b => b.Title.ToLower().Contains(searchQuery)).ToList();
if (searchResults.Count == 0)
{
Console.WriteLine("Aradığınız kritere uygun kitap bulunamadı.");
return;
}
Console.WriteLine("\nArama Sonuçları:");
foreach (var book in searchResults)
{
Console.WriteLine($"{book.Title} - {book.Author} ({book.Year})");
}
}
}
class Book
{
public string Title { get; set; }
public string Author { get; set; }
public int Year { get; set; }
}
}
