数组的Sort方法的用法

yuqi508 2005-06-04 04:16:04
现有结构体
Public Structure FriendItem
Public UserID As String
Public NickName As String
Public Email As String
Public UserFace As String
Public Status As Integer
End Structure
定义结构体数组Dim Friends() as FriendItem
并已付值
现在要用数组的Sort方法按Status 排序数组
请问怎么实现
...全文
80 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jhtchina 2005-06-11
  • 打赏
  • 举报
回复
msdn 里面查找Array.Sort或者ArrayList.Sort
marvelstack 2005-06-04
  • 打赏
  • 举报
回复
参考
using System;

namespace DotManagement.EntryManagement
{
public class FileItem :IComparable
{
private string fileName;

public FileItem(string fileName)
{
this.fileName = fileName;
}
public string FileName
{
get {return this.fileName;}
}


public int CompareTo(object obj)
{

//if (obj == null)
// return 1;

string compareFileName = ((FileItem)obj).FileName;

//if (this.FileName == compareFileName)
// return 0;
//if (this.FileName < compareFileName)
// return -1;
//if (this.FileName > compareFileName)
// return 1;
//return 0;
return this.FileName.CompareTo(compareFileName);
}
}
}
使用
ArrayList al = new ArrayList();
foreach(string fileName in Directory.GetFiles("c;\\"))
{
al.Add(new FileItem(fileName));
}
al.Sort();
ofei 2005-06-04
  • 打赏
  • 举报
回复
需要重载Sort()方法
找找资料~

110,529

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧