所以我知道有很多关于同一个问题的问题,并且有很多很好的答案,但我似乎仍然无法用我的代码解决我自己的问题。因此,我将非常感谢任何人提供的任何东西。我真的觉得我已经尝试了一切,我只是不知道问题可能是什么。我一直在努力。我想从列表中读取并将其写入控制台。但是当我尝试写它时它是空白的。
public class Admin
{
public void Maine()
{
List<Books> myLibraryBooks = new List<Books>();
Books book1 = new Books();
Console.Write("Enter Author Name:");
book1.Author = Console.ReadLine();
Console.Write("Enter Book Title:");
book1.Title = Console.ReadLine();
Console.Write("Enter Book ISBN:");
book1.ISBN = Console.ReadLine();
Console.Write("Enter the Publish Date:");
book1.Publish_Date = Console.ReadLine();
myLibraryBooks.Add(new Books() { Author = book1.Author.ToUpper(), Title = book1.Title.ToUpper(), ISBN = book1.ISBN, Publish_Date = book1.Publish_Date.ToUpper() });
Console.WriteLine("Book added Successfully");
Console.Write("Enter Author's Name:");
string input_to_find = Console.ReadLine();
var author = from Authors in myLibraryBooks
where Authors.Author == input_to_find
select Authors;
foreach (var book in author)
{
Console.WriteLine(book.Author, book.Title, book.ISBN, book.Publish_Date);
}
class Books
{
public string Author { get; set; }
public string Title { get; set; }
public string ISBN { get; set; }
public string Publish_Date { get; set; }
}