开发者

Use Linq instead of Icomparable

开发者 https://www.devze.com 2023-02-01 15:28 出处:网络
Every night I receive three excel sheets, at approximately the same time. Their names are: Open(todaysDate).xls , Closed(todaysDate).xls and Modified(todaysDate).xls

Every night I receive three excel sheets, at approximately the same time.

Their names are: Open(todaysDate).xls , Closed(todaysDate).xls and Modified(todaysDate).xls

I then read in all of these files into my application. Sometimes I do this reading ones a week, so I then need to sort all of the files, so they are synced in the right or开发者_如何学JAVAder. I managed to implement a sort function with Icomparable, but I would like it to work with Linq.

So my question is how do I write a Linq query to sort my List with first the criteria date(when it was created), and then by name, (I would like the order: Open, Modified, Closed).

Thankfull for all help!


Parse out the date into a DateTime and then you can use OrderBy on the datetime and then you can convert Open, Modified, Closed into integers 1, 2, 3 and do a ThenBy on that.

var fileList = readInList()
    .SortBy(file => ParseDate(file))
    .ThenBy(file => ParseType(file));

all you have to do is write the function ParseDate and ParseType

0

精彩评论

暂无评论...
验证码 换一张
取 消