数组如何排序 一个数组Item[] arr里面的对象是Item类型的Item有int类型的i属性 有string类型的s属性怎么根据Item的i或Item的s来排序 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 protected void Page_Load(object sender, EventArgs e) { Item o1 = new Item(1,"a"); Item o2 = new Item(3, "b"); Item o3 = new Item(5, "b"); Item o4 = new Item(2, "b"); Item o5 = new Item(4, "b"); Item[] aryItem = new Item[] { o1, o2, o3, o4, o5 }; myComparer cp = new myComparer(); Array.Sort(aryItem, cp); for (int i = 0; i < aryItem.Length; i++) { Response.Write(aryItem[i].i.ToString() + "<BR>"); } } public class myComparer : IComparer { #region IComparer 成员 public int Compare(object x, object y) { Item oItem1 = (Item)x; Item oItem2 = (Item)y; return oItem1.i - oItem2.i; } #endregion } public class Item { public int i; public string s; public Item(int i, string s) { this.i = i; this.s = s; } } 关于联表查询并更新数据 请教datacolumn 的使用 动态配置表单方案 文件操作之难题,高手来看!~ 网站人数统计怎么不行? 发布系统时.由于net framework版本引起的问题,大家帮我看看吧! 怎么实现产品图片更新? 高分求解:见内容 批处理更新数据库的语句 asp.net gridview与comparevalidator问题 要求已打开且可用的连接。连接的当前状态为已打开。 一个asp.net问题
protected void Page_Load(object sender, EventArgs e)
{
Item o1 = new Item(1,"a");
Item o2 = new Item(3, "b");
Item o3 = new Item(5, "b");
Item o4 = new Item(2, "b");
Item o5 = new Item(4, "b");
Item[] aryItem = new Item[] { o1, o2, o3, o4, o5 };
myComparer cp = new myComparer();
Array.Sort(aryItem, cp); for (int i = 0; i < aryItem.Length; i++)
{ Response.Write(aryItem[i].i.ToString() + "<BR>");
} } public class myComparer : IComparer
{ #region IComparer 成员 public int Compare(object x, object y)
{
Item oItem1 = (Item)x;
Item oItem2 = (Item)y;
return oItem1.i - oItem2.i;
} #endregion
}
public class Item
{
public int i;
public string s;
public Item(int i, string s)
{
this.i = i;
this.s = s;
}
}