コード例 #1
0
        public int CompareTo(object obj)
        {
            NoteBook book = (NoteBook)obj;

            if (Memory.CompareTo(book.Memory) != 0)
            {
                return(Memory.CompareTo(book.Memory));
            }
            if (Rating.CompareTo(book.Rating) != 0)
            {
                return(Rating.CompareTo(book.Rating));
            }
            if (Brend() && !book.Brend())
            {
                return(1);
            }
            if (!Brend() && book.Brend())
            {
                return(-1);
            }
            if (Cost.CompareTo(book.Cost) != 0)
            {
                return(Cost.CompareTo(book.Cost));
            }
            return(Model.CompareTo(book.Model));
        }
コード例 #2
0
 /// <summary>
 /// Compares the current instance with another object of the same type and returns an integer that
 /// indicates whether the current instance precedes, follows, or occurs in the same position in the
 /// sort order as the other object.
 /// </summary>
 /// <param name="other">An object to compare with this instance.</param>
 /// <returns>
 /// A 32-bit signed integer that indicates the relative order of the objects being compared.
 /// The return value has these meanings:
 /// Value
 /// Meaning
 /// Less than zero
 /// This instance is less than <paramref name="other"/>.
 /// Zero
 /// This instance is equal to <paramref name="other"/>.
 /// Greater than zero
 /// This instance is greater than <paramref name="other"/>.
 /// </returns>
 public int CompareTo(DistributionSuggestion other)
 {
     // Check if other is a null reference by using ReferenceEquals because
     // we overload the == operator. If other isn't actually null then
     // we get an infinite loop where we're constantly trying to compare to null.
     return(ReferenceEquals(other, null) ? 1 : Rating.CompareTo(other.Rating));
 }
コード例 #3
0
        public int CompareTo(BWeaponModifier other)
        {
            if (Rating != other.Rating)
            {
                return(Rating.CompareTo(other.Rating));
            }

            return(DamagePercentage.CompareTo(other.DamagePercentage));
        }
コード例 #4
0
 // This method is called by List().Sort() method to sort the list into Ascending Order
 public int CompareTo(Review other)
 {
     if (other == null)
     {
         return(1);
     }
     else
     {
         return(Rating.CompareTo(other.Rating));
     }
 }
コード例 #5
0
        // Sort the Restaurants reviews in either Ascending or Descending Order using the Ratings
        //public void SortReviews(string criteria)
        //{
        //    if (criteria.ToLower() == "ascending")
        //    {
        //        //_reviews.Sort();
        //    }
        //    else
        //    {
        //        //_reviews.Sort((a, b) => -1 * (a.CompareTo(b))); // Sort in descending order
        //    }
        //}

        // This method will compute the overall rating for the Restaurant based on all of the reviews
        //public double ComputeRating()
        //{
        //    double rating = 0.0;

        //    // Iterate through the reviews to grab each of the ratings
        //    foreach (var review in _reviews)
        //    {
        //        rating += review.Rating; // Add all of the ratings together
        //    }

        //    try
        //    {
        //        rating = rating / _reviews.Count();
        //    }
        //    catch (DivideByZeroException de)
        //    {
        //        logger.Error(de.Message);
        //    }

        //    return rating;
        //}

        // This method is call by the Sort() method to sort the List<Restaurants> in Ascending Order
        public int CompareTo(Restaurant other)
        {
            if (other == null)
            {
                return(1); // this object is greater as the other object isn't instantiated
            }
            else
            {
                return(Rating.CompareTo(other.Rating)); // Returns the greater one
            }
        }
コード例 #6
0
ファイル: Money.cs プロジェクト: romaaverkin/vendingMachine
 public int CompareTo(object obj)
 {
     if (obj is Money m)
     {
         return(Rating.CompareTo(m.Rating));
     }
     else
     {
         throw new Exception("Невозможно сравнить два объекта");
     }
 }