i would create a class to hold your information

public class namedate
    private string name;
    private datetime date;
    public string name
        get { return name; }
        set { name = value; }
    public datetime date
        get { return date; }
        set { date = value; }

i would then populate a list<namedate> to hold your items. when this is done, to sort the items you can use linq

list<namedate> somelist = new list<namedate>();
somelist = getnamedatelist();
var orderedbynamelist = somelist.orderby(e =>;
var orderedbydatetimelist = somelist.orderby(e =>;

i hope this helps.


something like this:

yourlist.orderby(o => o.datetime).thenby(o => o.number);


first you create two functions:

var sortbydate=(p=>;
var sortbyname=(p=>;

then you have, for example, a list containing the two

var sortdimensions=new list<object>({sortbydate,sortbyname});

then you if you want to sort by first date then name you do:


now, here is the tricky part, if you want to sort by name first then date you just alter the order of the functions in the sortdimensionslist:


this way, the same orderby statement will give you a different result.

ps. admittedly, this is rather close to being pseudocode since you may have to use something other than list<object> for the sortdimensions collection to avoid compiler errors, but i don't have access to an ide at the moment, but the spirit of the answer remains the same. create a collection, store delegate functions in it, then alter the order within the collection to achieve different sorting dimensions using the same generic code.


you can use linq function thenby after using orderby to perform further sorting.

listofrecords.orderby(p => =>

Related Query

More Query from same tag