Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Linq;
- using System.Text;
- /**
- @Author: Sajmon
- */
- namespace practise3
- {
- public class Employee : IComparable
- {
- private String name;
- private int salary;
- public Employee(String name, int sal) {
- this.name = name;
- this.salary = sal;
- }
- #region Properties
- public String Name {
- get
- {
- return this.name;
- }
- set
- {
- this.name = value;
- }
- }
- public int Salary {
- get {
- return this.salary;
- }
- set {
- this.salary = value;
- }
- }
- #endregion
- public int CompareTo(object obj)
- {
- Employee other = (Employee) obj;
- if (this.salary < other.salary) {
- return 1;
- }
- else if (this.salary > other.salary)
- {
- return -1;
- }
- else {
- return 0;
- }
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using practise3;
- /**
- @Author: Sajmon
- */
- namespace Program
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Employee> employees = new List<Employee>();
- employees.Add(new Employee("Peter", 3000));
- employees.Add(new Employee("Jano", 12500));
- employees.Add(new Employee("Fero", 17500));
- employees.Add(new Employee("Martin", 22500));
- employees.Add(new Employee("Andrej", 32500));
- employees.Add(new Employee("Jozko", 500));
- employees.Add(new Employee("Rado", 15500));
- employees.Add(new Employee("Miro", 18500));
- employees.Add(new Employee("Ondrej", 11500));
- employees.Sort();
- foreach (var item in employees) {
- Console.WriteLine(item.Name + ", " + item.Salary);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment