我有一个关于通过使用LINQ"搜索"其字段名来获取列表对象的问题.我为此编写了简单的类Library和Book类:
class Book
{
public string title { get; private set; }
public string author { get; private set; }
public DateTime indexdate { get; private set; }
public int page { get; private set; }
public Book(string title,string author, int page)
{
this.title = title;
this.author = author;
this.page = page;
this.indexdate = DateTime.Now;
}
}
class Library
{
List<Book> books = new List<Book>();
public void Add(Book book)
{
books.Add(book);
}
public Book GetBookByAuthor(string search) …Run Code Online (Sandbox Code Playgroud)