示例#1
0
 public int CompareTo(ComplexNumber other)
 {
     if (Iszero())
     {
         if (other.Iszero())
         {
             return(0);
         }
         return(other.RealPart != 0 ? -other.RealPart.CompareTo(0.0) : -other.ImaginaryPart.CompareTo(0.0));
     }
     if (other.Iszero())
     {
         return(-other.CompareTo(this));
     }
     if (other.Angle.Equals(Angle))
     {
         return(Radius.CompareTo(other.Radius));
     }
     throw new ArgumentException("cannot compare complexes of different arguments");
 }
        // ALTERNATIVE: could overload operators '>' and '<'.

        /// <summary>
        /// Implement IComparable interface.
        /// </summary>
        /// <param name="other"> Second circle </param>
        /// <returns> -1, 0, or 1 </returns>
        public int CompareTo(CircleS other) =>
        Radius.CompareTo(other.Radius);
 public int CompareTo([AllowNull] CircleS other) => Radius.CompareTo(other.Radius);
示例#4
0
 public int CompareTo(object obj)
 {
     return(Radius.CompareTo(((Circles)obj).Radius));
 }