-3

所以我知道有很多关于同一个问题的问题,并且有很多很好的答案,但我似乎仍然无法用我的代码解决我自己的问题。因此,我将非常感谢任何人提供的任何东西。我真的觉得我已经尝试了一切,我只是不知道问题可能是什么。我一直在努力。我想从列表中读取并将其写入控制台。但是当我尝试写它时它是空白的。

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; }
}
4

3 回答 3

1

一个错误 - 您拼错了入口点方法:

// Was Maine()
public void Main() 
{
于 2013-02-16T01:12:19.330 回答
0
var books = from book in myLibraryBooks
            where book.Author == input_to_find
            select book;

foreach (var book in books)
{
    Console.WriteLine(book.Author, book.Title, book.ISBN, book.Publish_Date);
}
于 2013-02-16T01:12:28.783 回答
0
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(book1);
        Console.WriteLine("Book added Successfully");


        Console.Write("Enter Author's Name:");
        string input_to_find = Console.ReadLine();

        var author = from Authors in myLibraryBooks
                     where StringComparer.OrdinalIgnoreCase.Equals(Authors.Author,input_to_find)
                     select Authors;

        foreach (var book in author)
        {
             Console.WriteLine(String.Format("{0} - {1} - {2} - {3}", 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; }
    }
}
于 2013-02-16T01:21:29.640 回答