Advertisement
Guest User

Untitled

a guest
May 22nd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. public class Pracownik : IComparable
  2. {
  3. protected string nazwisko;
  4. protected int id;
  5.  
  6. public Pracownik(string name, int id)
  7. {
  8. this.nazwisko = name;
  9. this.id = id;
  10. }
  11.  
  12. // inne metody
  13. public override string ToString()
  14. {
  15. return (nazwisko + ":" + id);
  16. }
  17.  
  18. public int CompareTo(object obj)
  19. {
  20. if (!(obj is Pracownik))
  21. throw new Exception("Obiekt nie jest pracownikiem");
  22. Pracownik tmp = (Pracownik)obj;
  23. switch(nazwisko.CompareTo(tmp.nazwisko))
  24. {
  25. case 0:
  26. return id.CompareTo(tmp.id);
  27. break;
  28. case 1:
  29. return 1;
  30. case -1:
  31. return -1;
  32. default:
  33. return 0;
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement