新建排序类,以用于List<T>的自定义排序

class MenuInfo : IComparable
{
public int order { get; set; }
public string menuid { get; set; }
public int CompareTo(object obj)
{
int result;
try
{
MenuInfo menuInfo = obj as MenuInfo;
if (this.order >= menuInfo.order)
{
result = 1;
}
else
{
result = -1;
}
return result;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}

posted @ 2020-02-13 16:05  一直的初学者  阅读(89)  评论(0编辑  收藏  举报