public int CompareTo(Person other)
 {
     if ((IsPI && !other.IsPI) || (!IsPI && other.IsPI))
     {
         if (IsPI)
         {
             return(-1);
         }
         else
         {
             return(1);
         }
     }
     else
     {
         int ret = LastName.CompareTo(other.LastName);
         if (ret == 0)
         {
             return(FirstName.CompareTo(other.FirstName));
         }
         else
         {
             return(ret);
         }
     }
 }
示例#2
0
        /// <summary>
        /// Funkcja ustawiająca prawidłowy pożądek obiektów klasy Person
        /// </summary>
        /// <param name="obj">objekt z którym poruwnuje aktualny obiekt (this)</param>
        /// <returns></returns>
        public int CompareTo(object obj)
        {
            Person p = obj as Person;

            // pierwsze pożądkujemy według nazwisk
            if (LastName != p.LastName)
            {
                return(LastName.CompareTo(p.LastName));
            }

            // następnie pożądkowanie według imion
            if (FirstName != p.FirstName)
            {
                return(FirstName.CompareTo(p.FirstName));
            }

            if (Age != p.Age)
            {
                return(Age.CompareTo(p.Age));
            }

            if (City != p.City)
            {
                return(City.CompareTo(p.City));
            }

            if (Email != p.Email)
            {
                return(Email.CompareTo(p.Email));
            }

            // na samym końcu sortowanie według numerów domu
            return(HomeNumber.CompareTo(p.HomeNumber));
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>
        /// Mniej niż zero - dana instancja ma wartość mneijszą niż obj
        /// Zero - dana instancja ma wartość równą obj
        /// Więcej niż zero - dana instancja ma wartość większą niż obj
        /// </returns>
        public int CompareTo(object obj)
        {
            int result;

            Contact contact = obj as Contact;

            if (obj == null)
            {
                // Dana instancja ma wartość większą niż obj.
                result = 1;
            }
            else if (obj.GetType() != typeof(Contact))
            {
                // Użycie w komunikacie operatora nameof z C# 6.0, aby
                // zapewnić spójność nazwy typu.
                throw new ArgumentException(
                          $"Parametr nie jest typu { nameof(Contact) }",
                          nameof(obj));
            }
            else if (Contact.ReferenceEquals(this, obj))
            {
                result = 0;
            }
            else
            {
                result = LastName.CompareTo(contact.LastName);
                if (result == 0)
                {
                    result = FirstName.CompareTo(contact.FirstName);
                }
            }
            return(result);
        }
示例#4
0
文件: Student.cs 项目: RobinJS/dotNET
        // comparing
        public int CompareTo(Student student2)
        {
            if (firstName.CompareTo(student2.firstName) != 0)
            {
                return(this.firstName.CompareTo(student2.firstName));
            }

            if (middleName.CompareTo(student2.middleName) != 0)
            {
                return(this.middleName.CompareTo(student2.middleName));
            }

            if (LastName.CompareTo(student2.LastName) != 0)
            {
                return(this.LastName.CompareTo(student2.LastName));
            }

            if (ssn.CompareTo(student2.ssn) != 0)
            {
                return(this.ssn.CompareTo(student2.ssn));
            }

            if (Phone.CompareTo(student2.Phone) != 0)
            {
                return(this.Phone.CompareTo(student2.Phone));
            }

            return(0);
        }
示例#5
0
        //..
        #region IComparable 멤버
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>
        /// Less than zero
        /// Zero
        /// Greater than zero
        /// </returns>

        public int CompareTo(object obj)
        {
            int     result;
            Contact contact = obj as Contact;

            if (obj == null)
            {
                // 이 인스턴스는  obj보다 크다
                result = 1;
            }
            else if (obj != typeof(Contanct))
            {
                // 메세지에서 c#6.0 nameof 연산자를 사용해 형식 이름에 일관성을 보장한다.
                throw new ArgumentException(
                          $"The parameter is not a of type {nameof(Contact)}", nameof(obj));
            }
            else if (Contact.ReferenceEquals(this, obj))
            {
                result = 0;
            }
            else
            {
                result = LastName.CompareTo(contact.LastName);
                if (result == 0)
                {
                    result = FitstName.CompareTo(contact.FitdtName);
                }
            }

            return(result);
        }
示例#6
0
        public int CompareTo(object obj)
        {
            StaffMember staff2        = (StaffMember)obj;
            int         compareResult = 0;

            // Compare Department
            compareResult = Department.Order.CompareTo(staff2.Department.Order);
            if (compareResult != 0)
            {
                return(compareResult);
            }

            // Compare Department Position
            compareResult = DepartmentPosition.Order.CompareTo(staff2.DepartmentPosition.Order);
            if (compareResult != 0)
            {
                return(compareResult);
            }

            // Compare Last Name
            compareResult = LastName.CompareTo(staff2.LastName);
            if (compareResult != 0)
            {
                return(compareResult);
            }

            // Compare First Name
            return(FirstName.CompareTo(staff2.FirstName));
        }
示例#7
0
        /// <summary>
        /// Compare two names to find if they are equal, or to find which is smaller
        /// </summary>
        /// <param name="other">the name to be compared to</param>
        /// <returns>Less than Zero: this precedes other in the sort order,
        ///Zero: both Names are in the same postion,
        ///greater then Zero: this follows other in sort order </returns>
        public int CompareTo(Name other)
        {
            int result;

            result = LastName.CompareTo(other.LastName); //Last Names

            if (result != 0)
            {
                return(result);
            }

            int leng = Math.Min(GivenNames.Length, other.GivenNames.Length); //GivenNames

            for (int g = 0; g < leng; g++)
            {
                result = GivenNames[g].CompareTo(other.GivenNames[g]);
                if (result != 0)
                {
                    return(result);
                }
            }

            result = GivenNames.Length.CompareTo(other.GivenNames.Length); //Unequall number of GivenNames
            if (result != 0)
            {
                return(result);
            }

            return(result); //Same (baseCase)
        }
示例#8
0
        // 我们在这里定义一个预处理的指令,但是他不会执行。
        #region  IComparable Members
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>
        /// Less than zero:      This instance is less than obj
        /// Zero                 This instance is equal to obj
        /// Greater than zero    This instance is greater than obj
        /// </returns>
        #endregion

        // 开始定义一个新的方法
        public int CompareTo(object obj)
        {
            int     result;
            Contact contact = obj as Contact;

            if (obj == null)
            {
                result = 1;
            }
            else if (obj.GetType() != typeof(Contact))
            {
                throw new ArgumentException(
                          $"The parameter is not a value of type {nameof(Contact)}",
                          nameof(obj));
            }
            else if (Contact.ReferenceEquals(this, obj))
            {
                result = 0;
            }
            else
            {
                result = LastName.CompareTo(contact.LastName);
                if (result == 0)
                {
                    result = FirstName.CompareTo(contact.FirstName);
                }
                {
                }
            }

            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>
        /// Less than zero:      This instance is less than obj
        /// Zero                 This instance is equal to obj
        /// Greater than zero    This instance is greater than obj
        /// </returns>
        public int CompareTo(object obj)
        {
            int     result;
            Contact contact = obj as Contact;

            if (obj == null)
            {
                // This instance is greater than obj
                result = 1;
            }
            else if (obj.GetType() != typeof(Contact))
            {
                // Use C# 6.0 nameof operator in message to
                // ensure consistency in the Type name
                throw new ArgumentException(
                          $"The parameter is not a value of type { nameof(Contact) }",
                          nameof(obj));
            }
            else if (Contact.ReferenceEquals(this, obj))
            {
                result = 0;
            }
            else
            {
                result = LastName.CompareTo(contact.LastName);
                if (result == 0)
                {
                    result = FirstName.CompareTo(contact.FirstName);
                }
            }
            return(result);
        }
示例#10
0
 public int CompareTo(ContactInfo other)
 {
     if (Object.ReferenceEquals(other, null))
     {
         return(1);
     }
     return((LastName.CompareTo(other.LastName) == 0) ? FirstName.CompareTo(other.FirstName) : LastName.CompareTo(other.LastName));
 }
示例#11
0
 public int CompareTo(Student otherStudent)
 {
     if (LastName == otherStudent.LastName)
     {
         return(FirstName.CompareTo(otherStudent.FirstName));
     }
     return(LastName.CompareTo(otherStudent.LastName));
 }
示例#12
0
 public int CompareTo(object obj)
 {
     if (obj is Student)
     {
         return(LastName.CompareTo((obj as Student).LastName));
     }
     throw new NotImplementedException();
 }
示例#13
0
 public int CompareTo(ContactData other)
 {
     if (Object.ReferenceEquals(other, null))
     {
         return(1);
     }
     return(Name.CompareTo(other.Name) & LastName.CompareTo(other.LastName));
 }
        public int CompareTo(ContactData other)
        {
            int result = Name.CompareTo(other.Name);

            if (result == 0)
            {
                result = LastName.CompareTo(other.LastName);
            }
            return(result);
        }
示例#15
0
        public int CompareTo(object obj)
        {
            var person = obj as Person;

            if (person == null)
            {
                throw new ArgumentException("Illigaler Typ");
            }
            return(LastName.CompareTo(person.LastName));
        }
示例#16
0
        public int CompareTo(object obj)
        {
            Student otherStudent = obj as Student;

            if (otherStudent == null)
            {
                return(-1);
            }
            return(LastName.CompareTo(otherStudent.LastName));
        }
示例#17
0
        public int CompareTo(Human obj)
        {
            int output = LastName.CompareTo(obj.LastName);

            if (output == 0)
            {
                output = BirthDate.CompareTo(obj.BirthDate);
            }
            return(output);
        }
示例#18
0
        public int CompareTo(Racer other)
        {
            int compare = LastName?.CompareTo(other?.LastName) ?? -1;

            if (compare == 0)
            {
                return(FirstName?.CompareTo(other?.FirstName) ?? -1);
            }
            return(compare);
        }
示例#19
0
 public virtual int CompareTo(ArchivedStudent other)
 {
     // Alphabetic sort by firstname if lastname is equal. [A to Z]
     if (LastName == other.LastName)
     {
         int result = FirstName.CompareTo(other.FirstName);
         return(result);
     }
     // Default lastname sort. [A to Z]
     return(LastName.CompareTo(other.LastName));
 }
示例#20
0
        public int CompareTo(object obj)
        {
            Student compareTo = (Student)obj;
            int     lastnames = LastName.CompareTo(compareTo.LastName);

            if (lastnames == 0)
            {
                return(FirstName.CompareTo(compareTo.FirstName));
            }
            return(lastnames);
        }
        public int CompareTo(Employee other)
        {
            int compareResult = LastName.CompareTo(other.LastName);

            if (compareResult == 0)
            {
                compareResult = FirstName.CompareTo(other.FirstName);
            }

            return(compareResult);
        }
示例#22
0
 public int CompareTo(ContactData other)
 {
     if (object.ReferenceEquals(other, null))
     {
         return(1);
     }
     if (FirstName.CompareTo(other.FirstName) == 0)
     {
         return(LastName.CompareTo(other.LastName));
     }
     return(FirstName.CompareTo(other.FirstName));
 }
        public int CompareTo([AllowNull] Racer other)
        {
            //先比较LastName
            int compare = LastName?.CompareTo(other?.LastName) ?? -1;

            //如果LastName相同就比较FirstName
            if (compare == 0)
            {
                return(FirstName?.CompareTo(other?.FirstName) ?? -1);
            }
            return(compare);
        }
示例#24
0
 public int CompareTo(ContactData other)
 {
     if (Object.ReferenceEquals(other, null))
     {
         return(1);
     }
     if (LastName.CompareTo(other.LastName) == 0) //сравниваем фамилии, потом уже имена
     {
         return(FirstName.CompareTo(other.FirstName));
     }
     return(LastName.CompareTo(other.LastName));
 }
示例#25
0
        public int CompareTo(object o)
        {
            Person p = o as Person;

            if (p != null)
            {
                return(LastName.CompareTo(p.LastName));
            }
            else
            {
                throw new Exception("Невозможно сравнить два объекта");
            }
        }
示例#26
0
        public bool Equals(ContactData other)
        {
            if (Object.ReferenceEquals(other, null))
            {
                return(false);
            }

            if (Object.ReferenceEquals(this, other))
            {
                return(true);
            }
            return(FirstName.CompareTo(other.FirstName) == 0 && LastName.CompareTo(other.LastName) == 0);
        }
示例#27
0
 // IComparable - this allows it to be used in a SortedList, and also ArrayList.Sort, or other <collection>.Sort methods...
 // Return values:
 //  Less than zero - This instance is less than obj.
 //  Zero - This instance is equal to obj.
 //  Greater than zero - This instance is greater than obj.
 public int CompareTo(object o)
 {
     if (o is Person) // check to ensure the object is as we expect
     {
         Person other = (Person)o;
         if (LastName != other.LastName)
         {
             return(LastName.CompareTo(other.LastName)); // If we have different surnames, sort via this first.
         }
         return(FirstName.CompareTo(other.FirstName));   // if our surnames are the same, then compare the firstnames
     }
     throw new ArgumentException("object is not a Person");
 }
 public override int CompareTo(ArchivedStudent other)
 {
     if (FinalScore == other.FinalScore)
     {
         int result = LastName.CompareTo(other.LastName);
         if (FinalScore == other.FinalScore)
         {
             int result2 = FirstName.CompareTo(other.FirstName);
             return(result2);
         }
         return(result);
     }
     return(FinalScore.CompareTo(other.FinalScore));
 }
示例#29
0
        public int CompareTo(UserData other)
        {
            if (Object.ReferenceEquals(other, null))
            {
                return(1);
            }
            int result = FirstName.CompareTo(other.FirstName);

            if (result == 0)
            {
                result = LastName.CompareTo(other.LastName);
            }
            return(result);
        }
示例#30
0
 public int CompareTo(UserData other)
 {
     if (Object.ReferenceEquals(other, null))
     {
         return(1);
     }
     if (FirstName.CompareTo(other.FirstName) == 0)
     {
         return(LastName.CompareTo(other.LastName));
     }
     else
     {
         return(FirstName.CompareTo(other.FirstName));
     }
 }