Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ComparingObjects
  4. {
  5. public class Person : IComparable<Person>
  6. {
  7. public string Name { get; private set; }
  8. public int Age { get; private set; }
  9. public string Town { get; private set; }
  10.  
  11. public Person(string name, int age, string town)
  12. {
  13. this.Name = name;
  14. this.Age = age;
  15. this.Town = town;
  16. }
  17.  
  18. public int CompareTo(Person other)
  19. {
  20. int result = this.Name.CompareTo(other.Name);
  21. if (result == 0) result = this.Age.CompareTo(other.Age);
  22. if (result == 0) result = this.Town.CompareTo(other.Town);
  23. return result;
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement