本文整理汇总了C#中Book.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Book.Equals方法的具体用法?C# Book.Equals怎么用?C# Book.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Book
的用法示例。
在下文中一共展示了Book.Equals方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Book_Equal
public void Test_Book_Equal()
{
Book book1 = new Book { Name = "Book 1" };
Book book2 = new Book { Name = "Book 1" };
Book book3 = new Book { Name = "Book 2" };
Assert.IsTrue(book1.Equals(book2));
Assert.IsFalse(book1.Equals(book3));
}
示例2: RemoveBook
public void RemoveBook(Book toRemove)
{
if (toRemove == null)
{
throw new ArgumentNullException("toRemove");
}
int index = list.FindIndex((Book book) => toRemove.Equals(book));
if (index == -1)
{
logger.Error("List doesn't contain this book");
throw new ArgumentException("List doesn't contain this book", "toRemove");
}
list.Remove(toRemove);
}
示例3: AddBook
public void AddBook(Book toAdd)
{
if (toAdd == null)
{
throw new ArgumentNullException("toAdd");
}
int index = list.FindIndex((Book book) => toAdd.Equals(book));
if (index != -1)
{
logger.Error("List already contains this book");
throw new ArgumentException("List already contains this book", "toAdd");
}
list.Add(toAdd);
}
示例4: AddBook
public void AddBook(Book book)
{
logger.Trace("Starting AddBook method");
if (book == null)
throw new ArgumentNullException();
var foundBook = list.FirstOrDefault(b => book.Equals(b));
if (foundBook == null)
{
list.Add(book);
Repository.Save(list);
}
else
{
var e = new Exception("This book exists in repository");
logger.Error(e, "Exception in AddBook method");
throw e;
}
logger.Trace("AddBook method finished");
}