我有一个关于通过使用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) public class Person {
private String name;
public Person(String name) {
this.name = name;
}
public boolean equals(Person p) {
System.out.println("..............");
return p.name.equals(this.name);
}
}
Run Code Online (Sandbox Code Playgroud)
嗨,我正在通过OCJP问答并回答这个问题是 equals方法没有正确覆盖Object.equlas方法.
我认为用名称来覆盖这里是多余的,但是这个问题的答案也是不正确的.
能不能指出我在这里缺少什么概念......
注意:没有选项说覆盖hasCode和equlas与此问题具有相同的参数...