如何使用 lambda 或 linq 排列列表。 以下是列表(Tickets),该列表有一个名为“MessageId”的字段,每个MessageId可能包含也可能不包含子消息等(即ReplyMessageId)。
我有以下列表
MessageId ReplyMessageId Message PostedDate
66 65 "Hello" 6/25/2013 10:00:01 AM
68 66 "[Reply to Hello]-1" 6/25/2013 10:12:23 AM
72 66 "[Reply to Hello]-2" 6/25/2013 11:12:23 AM
73 66 "[Reply to Hello]-3" 6/26/2013 9:12:23 AM
74 66 "[Reply to Hello]-4" 6/25/2013 11:12:12 PM
75 68 "[Reply to Hello-1] -1" 6/25/2013 11:05:12 AM
76 73 "[Reply to Hello-3] -1" 6/26/2013 10:10:23 AM
80 75 "[Reply to Hello-1-1] -1" 6/25/2013 11:45:22 AM
81 68 "[Reply to Hello-1]-1" 6/25/2013 11:45:22 AM
例如,MessageId 68 是 MessageId 66 和 MessageId 68 具有子消息 75,81 的回复。
输出列表应采用以下格式。
MessageId ReplyMessageId Message PostedDate
66 65 "Hello" 6/25/2013 10:00:01 AM
74 66 "[Reply to Hello]-4" 6/25/2013 11:12:12 PM
73 66 "[Reply to Hello]-3" 6/26/2013 9:12:23 AM
76 73 "[Reply to Hello-3]-1" 6/26/2013 10:10:23 AM
72 66 "[Reply to Hello]-2" 6/25/2013 11:12:23 AM
68 66 "[Reply to Hello]-1" 6/25/2013 10:12:23 AM
81 68 "[Reply to Hello-1]-1" 6/25/2013 11:45:22 AM
75 68 "[Reply to Hello-1]-1" 6/25/2013 11:05:12 AM
80 75 "[Reply to Hello-1-1]-1" 6/25/2013 11:45:22 AM