当前位置: 首页>>代码示例>>C#>>正文


C# Book.Equals方法代码示例

本文整理汇总了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));
        }
开发者ID:mercurysn,项目名称:MyBookLibrary,代码行数:9,代码来源:BookModelTests.cs

示例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);
 }
开发者ID:VladSamodin,项目名称:ASP.NET.Samodin.Day5,代码行数:14,代码来源:BookListService.cs

示例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);
 }
开发者ID:VladSamodin,项目名称:ASP.NET.Samodin.Day5,代码行数:14,代码来源:BookListService.cs

示例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");
 }
开发者ID:kirill-vinnichek,项目名称:BSU.ASP.1501.Day5.Vinnichek,代码行数:19,代码来源:BookListService.cs


注:本文中的Book.Equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。