score:0

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 => e.name);
var orderedbydatetimelist = somelist.orderby(e => e.date);

i hope this helps.

score:4

something like this:

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

score:4

first you create two functions:

var sortbydate=(p=>p.date);
var sortbyname=(p=>p.name);

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:

mylist.orderby(sortdimensions[0]).thenby(sortdimensions[1]);

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:

sortdimensions.remove(sortbyname);
sortdimensions.insert(0,sortbyname);

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.

score:6

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

listofrecords.orderby(p => p.name).thenby(p => p.date)

Related Query

More Query from same tag