Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Pracownik : IComparable
- {
- protected string nazwisko;
- protected int id;
- public Pracownik(string name, int id)
- {
- this.nazwisko = name;
- this.id = id;
- }
- // inne metody
- public override string ToString()
- {
- return (nazwisko + ":" + id);
- }
- public int CompareTo(object obj)
- {
- if (!(obj is Pracownik))
- throw new Exception("Obiekt nie jest pracownikiem");
- Pracownik tmp = (Pracownik)obj;
- switch(nazwisko.CompareTo(tmp.nazwisko))
- {
- case 0:
- return id.CompareTo(tmp.id);
- break;
- case 1:
- return 1;
- case -1:
- return -1;
- default:
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement