Using system;
Using system. collections;
Comparison and sorting of namespace Sets
{
Public class efficience: icomparable
{
Private int workhour;
Private int output;
Int icomparable. compareto (Object OBJ)
{
If (OBJ = NULL)
Throw new argumentexception ("comparison object cannot be blank ");
If (! OBJ. GetType (). Equals (this. GetType ()))
Throw new argumentexception ("different types of comparison ");
Efficience objeffic = (efficience) OBJ;
If (this. effic> objeffic. effic)
Return 1;
If (this. effic Return-1;
Return 0;
}
Public int workhour
{
Set
{
If (value throw new argumentexception ("the working time cannot be {0} or a negative number ");
Workhour = value;
}
}
Public int output
{
Set
{
If (value throw new argumentexception ("work output cannot be negative ");
Output = value;
}
}
Public float effic
{
Get
{
Return (float) output/(float) workhour;
}
}
}
Class class1
{
[Stathread]
Static void main (string [] ARGs)
{
Random Rand = new random ();
Efficience [] effics = new efficience [5];
String [] persons = {"Xiaohua", "Diana", "Yanyan", "zhulin", "Lixin "};
Console. writeline ("generated effics array ");
// Console. writeline ("effics. getlowerbound (0) = {0}, effics. getupperbound (0) = {1} ", effics. getlowerbound (0), effics. getupperbound (0 ));
For (INT I = effics. getlowerbound (0); I {
Effics [I] = new efficience ();
Effics [I]. workhour = Rand. Next () % 24;
Effics [I]. Output = Rand. Next () % 1000;
Console. writeline ("person = {0}, effic = {1}", persons [I], effics [I]. effic );
}
Sortedlist = new sortedlist ();
For (INT I = effics. getlowerbound (0); I {
Sortedlist. Add (effics [I], persons [I]);
}
Console. writeline ("read content from sortedlist ");
Foreach (efficience effic in sortedlist. getkeylist ())
{
Console. writeline ("person = {0}, effic = {1}", sortedlist [effic], effic. effic );
}
Console. Read ();
}
}
}