using System;
namespace Example54
{
class Employee : IComparable
{
private int id;
private double salary;
public Employee(int id, double salary)
{
this.id = id;
this.salary = salary;
}
public int ID
{
get { return id; }
set { id = value; }
}
public double Salary
{
get { return salary; }
set { salary = value; }
}
public override string ToString()
{
return "Id= " + id + " salary= " + salary;
}
#region IComparable Members
public int CompareTo(object obj)
{
Employee temp = (Employee) obj;
if (this.id < temp.id)
return -1;
else
if (this.id == temp.id)
return 0;
else
return 1;
}
#endregion
}
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
Employee[] emp = new Employee[]
{ new Employee(333, 10.50), new Employee(111, 20.50),
new Employee(222, 17.55) };
foreach (Employee e in emp)
{
Console.WriteLine(e);
}
Array.Sort(emp);
foreach (Employee e in emp)
{
Console.WriteLine(e);
}
}
}
}