排序自定义类列表&LT; T&GT; [英] Sort a Custom Class List<T>
本文介绍了排序自定义类列表&LT; T&GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想我的排序名单与日期
属性。
I would like to sort my list with the date
property.
这是我的自定义类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Test.Web
{
public class cTag
{
public int id { get; set; }
public int regnumber { get; set; }
public string date { get; set; }
}
}
这是这是列表
,我想排序:
List<cTag> Week = new List<cTag>();
我想要做的排序是由日期
的CTAG类的财产清单。
日期IST格式:DD.MM.YYYY
What I want to do is sort the List by the date
property of the cTag class.
The date ist in the format: dd.MM.yyyy.
我看了一些关于 IComparable的
界面,但不知道如何使用它。
I read something about the IComparable
interface, but don't know how to use it.
推荐答案
这样做的一个方法是使用代表
One way to do this is with a delegate
List<cTag> week = new List<cTag>();
// add some stuff to the list
// now sort
week.Sort(delegate(cTag c1, cTag c2) { return c1.date.CompareTo(c2.age); });
这篇关于排序自定义类列表&LT; T&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文