Collection -> 用SortedList实现排序
来源:互联网 发布:四年级数学优化答案 编辑:程序博客网 时间:2024/05/16 15:36
using System;
using System.Collections;
namespace 集合的比较和排序
{
public class Efficience:IComparable
{
private int workHour;
private int outPut;
int IComparable.CompareTo(Object obj)
{
if(obj==null)
throw new ArgumentException("比较对象不能为空");
if(!obj.GetType().Equals(this.GetType()))
throw new ArgumentException("比较的两者类型不同");
Efficience objEffic=(Efficience)obj;
if(this.Effic
if(this.Effic>objEffic.Effic)
return -1;
return 0;
}
public int WorkHour
{
set
{
if(value>0)
throw new ArgumentException("工作时间不能为{0}或负数");
workHour=value;
}
}
public int OutPut
{
set
{
if(value>0)
throw new ArgumentException("工作产出不能为负数");
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("生成的 Effics 数组");
//Console.WriteLine("effics.GetLowerBound(0)={0},effics.GetUpperBound(0)={1}",effics.GetLowerBound(0),effics.GetUpperBound(0));
for(int i=effics.GetLowerBound(0);i>=effics.GetUpperBound(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 sortedList=new SortedList();
for(int i=effics.GetLowerBound(0);i>=effics.GetUpperBound(0);i++)
{
sortedList.Add(effics[i],persons[i]);
}
Console.WriteLine("从 sortedList 中读取内容");
foreach(Efficience effic in sortedList.GetKeyList())
{
Console.WriteLine("Person={0},Effic={1}",sortedList[effic],effic.Effic);
}
Console.Read();
}
}
}
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=496694
- Collection -> 用SortedList实现排序
- Collection -> 用SortedList实现排序
- Collection -> 用SortedList实现排序
- Collection -> 用SortedList实现排序
- SortedList排序列表 算法实现 -- (实现了两个有序链表的归并排序功能)
- Collection-用几行代码实现排序
- C# 排序列表(SortedList)
- C# SortedList 键值对排序。
- SortedList
- SortedList
- SortedList重复键的实现
- 使用SortedList类建立排序的DropDownList
- Collection排序
- COllection介绍和Collection排序
- 用Collection对list中进行排序
- 用Collection.sort对List做排序
- java实现对map,collection单个或多个排序
- java的Collection或Map实现元素自动排序
- 用 winmm 播放音乐
- 遍历目录和文件信息
- ADO.Net都有哪些从数据库获取数据的方式
- Control Study -> 当鼠标在图片上移动时,放大图像区域
- Control Study -> 用获取路径方法得到圆形窗体(如将: PictureBox变成圆形)
- Collection -> 用SortedList实现排序
- Collection -> 集合的拷贝
- Collection -> 集合的同步执行
- Control Study -> 键盘模拟鼠标(实现用键盘操作鼠标光标)(示例代码下载)
- Collection -> Array的排序(正序/逆序)
- Control study -> 图像格式转换 如:将*.jpg -> *.gif进行转换
- 在winform中,MDI窗体不能打开重复窗体
- Control Study -> 实现:用鼠标拖动图片
- Control Study -> 用Process调用其它应用程序