-3

So I know there is a lot of questions asked on this same exact question, and there are a lot of great answers but still I can't seem to fix my own problem with my code. So I will GREATLY appreciate anything anyone has to offer. I really feel like I have tried everything and I just have no idea what the problem may be. I have been working on this forever. I want to Read from the List and write it to the Console. But When I try to write it it is blank.

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

3 Answers3

1

One error - you misspelled the entry point method:

// Was Maine()
public void Main() 
{
Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
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);
}
Christoffer Lette
  • 14,346
  • 7
  • 50
  • 58
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; }
    }
}
Calvin Allen
  • 4,176
  • 4
  • 31
  • 31