Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Project_1
- {
- class Employee : Human
- {
- public int ID;
- public float salary;
- public Employee(int id, string name, float salary)
- {
- this.name = name;
- ID = id;
- this.salary = salary;
- }
- //for icomparable
- //public int CompareTo(object obj)
- //{
- // Employee e = (Employee)obj;
- // //return (this.Salary.CompareTo(e.Salary));
- // if (this.salary == e.salary)
- // {
- // return 0;
- // }
- // else
- // {
- // if (this.salary < e.salary)
- // {
- // return -1;
- // }
- // else
- // {
- // return 1;
- // }
- // }
- //}
- //public int CompareTo(Employee other)
- //{
- // return salary.CompareTo(other.salary);
- //}
- }
- class EmployeeSort : IComparer<Employee>
- {
- public enum sortBy
- {
- ID,
- name,
- salary
- }
- public sortBy sortChoice = sortBy.salary;
- public int Compare(Employee x, Employee y)
- {
- switch (sortChoice)
- {
- case sortBy.ID:
- return x.ID.CompareTo(y.ID);
- case sortBy.name:
- return x.name.CompareTo(y.name);
- case sortBy.salary:
- return x.salary.CompareTo(y.salary);
- default:
- Console.WriteLine("Error, invalid choice");
- break;
- }
- return x.salary.CompareTo(y.salary);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement